0

我有一个 iframe,其中包含以下代码:

$(document).ready(function(){
    $('.checksum').click(function(){
        window.parent.Clickarunsuministro($(this).val());
    })
})

当您单击时.checksum,我想调用父级中的函数。它在 Chrome 和 IE 中完美运行,但在 Firefox 中却不行。

出现的错误是:

Permission denied to access property 'Clickarunsuministro'

任何想法可能是什么问题?

4

2 回答 2

0

您可以尝试使用 jquery 自定义事件

在 iframe 中

$(document).ready(function(){
    $('.checksum').click(function(){
        $(window).trigger('clickarunsuministro', {data: $(this).val()})
    })
})

在父母

$('<frame-selector>').on('clickarunsuministro', function(event){
    console.log('data', event.data)
})
于 2013-06-21T03:30:53.317 回答
0

出于安全原因,通常不允许 iframe 及其运行的页面直接交互。相反,您可以使用message事件在拥有文档和 iframe 之间发送字符串和 json 对象。请参阅https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage?redirectlocale=en-US&redirectslug=DOM%2Fwindow.postMessage了解有关方式和原因的一些详细信息。

您的代码现在可能在 Chrome 和 IE 中工作,但可以肯定的是,它很快就不会了,所以在这种情况下最好让您的代码适应未来。

于 2013-06-21T03:22:01.040 回答