Firefox-Javascript-window.event无法存活传递到context.apply()
Firefox - Javascript - window.event not surviving pass to context.apply()
-这是留给后代的原始问题-
我写的一段新代码有点麻烦。我正试图找到发送消息的窗口所在的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);
在Chrome/Safari中运行良好,但Firefox每次都匹配第一个frame
。(iframe.contentWindow === window
,而不管哪个window
)。事实上,我最初在这里的另一篇文章中找到了如何做到这一点,尽管他们没有提到Firefox的问题。
每个iframe都有不同的src。
有不同的匹配方法吗?我做错了什么吗?
请不要jQuery
感谢
更好的问题:
我的事件是通过窗口对象通过function.apply(window, params)
传递的,期望它所应用的函数中有window.event可用-这在Chrome/Safari中有效,但在FF中却不是这样。我如何在FF中传递事件?
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);
相关文章:
- Javascript:如何获取函数.apply()的键
- 另一个if(!$scope.$$phase)$scope$apply()szenario-需要帮助才能通关
- call()和apply()实际上是用来欺骗方法处理类似数组的对象的
- Angular Apply已经在进行中
- 是否可以在不更改上下文的情况下调用函数.apply
- Error: timers.js:234 callback.apply(timer, args);
- 在lodash上有没有一个替代方案.merge.apply(_,x);其中x是对象的数组
- How to apply javascript on <asp:Buttonfield>?
- $scope.apply()何时应用于angular
- 将参数作为不带.apply()的数组传递
- AngularJS$apply有时不会;当在highchart中使用click事件时,t触发更新{{}}中html标记中
- 如何通过 Function.prototype.apply() 更改调用函数的参数
- 如何向.apply()方法添加回调
- 在使用AngularJS时,我应该在$apply和$watch之间使用哪个
- jquery.proxy in the bootstrap-typeahead.js context
- 使用$scope的最佳实践$apply();或者甚至是使用Angular Component的非Angular内容中的$
- context.arc(x,y,r,S角度,E角度,逆时针);我可以在画布上做z方向的移动吗
- 通过fn.apply或fn.bind将函数传递给setTimeout
- Angular $scope更新、导航和 $scope.$apply() 后不绑定到视图
- Firefox-Javascript-window.event无法存活传递到context.apply()