3

我的网站中有一个 iframe,并且想在 iframe 之外触发一个点击事件。iframe 作为灯箱加载,iframe 中有一个表单,我想在提交时关闭灯箱。

我使用此代码,但单击事件不起作用。当我在萤火虫中运行相同的代码时,灯箱成功关闭,但在这里我没有得到任何结果。

$('iframe', parent.document)
    .parent('div#pp_full_res .pp_pic_holder')
    .siblings('div.pp_details')
    .find('a.pp_close')
    .click();
4

2 回答 2

1

考虑改为在父框架中调用函数。如果 iframe 中的文档遵循相同的来源策略,则可以执行以下操作:

window.parent.closeLightbox();

然后该closeLightbox()函数应该包含您在 Firebug 中测试过的代码。

于 2012-10-09T12:37:31.400 回答
0

iframe 内的操作无法在父窗口中执行脚本,或访问父 DOM

编辑:看看使用 jquery .hide 隐藏 iframe

于 2012-10-09T10:47:08.170 回答