Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/378.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firefox-Javascript-window.event无法传递到context.apply()_Javascript_Firefox_Iframe_Window_Postmessage - Fatal编程技术网

Firefox-Javascript-window.event无法传递到context.apply()

Firefox-Javascript-window.event无法传递到context.apply(),javascript,firefox,iframe,window,postmessage,Javascript,Firefox,Iframe,Window,Postmessage,-这是留给后代的原始问题- 我写的一段新代码有点麻烦。我试图找到发送消息的窗口所在的iframe,假设它来自iframe。有关守则: var getContainingFrame = function(source){ var frames = document.getElementsByTagName('iframe'); for (var i = 0; i < frames.length; ++i) { if (frames[i].contentWind

-这是留给后代的原始问题-

我写的一段新代码有点麻烦。我试图找到发送消息的窗口所在的iframe,假设它来自iframe。有关守则:

var getContainingFrame = function(source){
    var frames = document.getElementsByTagName('iframe');
    for (var i = 0; i < frames.length; ++i) {
        if (frames[i].contentWindow === source) {
            return frames[i];
        }
    }
    return false;
}
var postMessageReceivedCallback = function(event){
    getContainingFrame(event.source);
}
window.addEventListener("message", postMessageReceivedCallback, false);
var getContainingFrame=函数(源){
var frames=document.getElementsByTagName('iframe');
对于(变量i=0;i
在Chrome/Safari中运行良好,但是Firefox每次都匹配第一个
帧。(
iframe.contentWindow===window
无论哪个
窗口
)。事实上,我最初是在另一篇文章中发现如何做到这一点的,尽管他们没有提到Firefox的问题

每个iframe都有一个不同的src

是否有不同的方法来匹配这些?我做错什么了吗

请不要用jQuery。

谢谢

更好的问题:


我的事件是通过一个
函数传递的。apply(window,params)
通过window对象传递的,期望window.event在它所应用的函数中可用-这在Chrome/Safari中有效,但在FF中不是这样。如何在FF中传递事件?

iFrame是否跨原点?有什么原因不能直接检查src吗?@ReubenMorais是的,它们是交叉源代码。我刚刚试过这个,据我所知,它工作得很好。你能链接到一个完整的页面,为你显示问题吗?@BorisZbarsky因为它位于一个内部服务器的安全层后面,我不能。我正在努力得到一个更健壮的小提琴示例。尽管进一步的测试表明,对事件调度窗口的引用可能会完全丢失。。。我将通过其他函数传递此信息,上面的示例只是其中的亮点。很快。@RandyHall好的,让我知道!
var someFunction = function(params){
    this.event.source //expect this to be the window the event originated in
    //... do something, like the iframe check
}
var postMessageReceivedCallback = function(event){
    //FF not keeping the event reference on the window that other browsers are,
    //so we add it ourselves from the event object passed by the message event.
    window.event = event;
    someFunction.apply(window, event.message);
}
window.addEventListener("message", postMessageReceivedCallback, false);