本文介绍了Opera:无法从window.open()获取加载事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var openedWindow = window.open("test.html", "title");

openedWindow.addEventListener("load", function() {
    console.log("received load event");
}, false);

我想从打开的窗口中获取加载事件.上面的代码有效,但是在Opera 11.62中不会调用回调函数(在其他浏览器上有效).

I want to get the load event from an opened window. The code above works, but the callback function does not get called in Opera 11.62 (works on other browser).

0ms超时后我注册事件时有效:

It works when i register the event after 0ms timeout:

var openedWindow = window.open("test.html", "title");

window.setTimeout(function() {
    openedWindow.addEventListener("load", function() {
        console.log("received load event");
    }, false);
}, 0);

推荐答案

这似乎是Opera中的一个已知错误-我已将内部错误报告(CORE-46278)向前推了一点.

this seems to be a known bug in Opera - I've pushed the internal bug report (CORE-46278) a little bit forward.

我能想到的唯一解决方法是从弹出内容添加回调-键入opener.popupLoaded().但是,这也可能会带来性能上的优势-您可以在弹出窗口的脚本环境准备好并且您要与之对话的脚本正在运行时开始与该弹出窗口进行交互,而不必等待加载事件.

The only workaround I can think of is adding callbacks from the popup contents - type opener.popupLoaded(). This may however offer a performance advantage too - you can start interacting with the popup when its script environment is ready and the script you want to talk to is running, rather than waiting for the load event.

这篇关于Opera:无法从window.open()获取加载事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 15:49