检测用window.open打开的窗口的onload事件 [英] Detecting the onload event of a window opened with window.open

查看:141
本文介绍了检测用window.open打开的窗口的onload事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 window.popup = window.open($(this).attr('href'), 'Ad', 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');
 $(window.popup).onload = function()
        {
                alert("Popup has loaded a page");
        };

这不适用于任何浏览器(IE,Firefox,Chrome) 。我怎么能检测到一个页面加载窗口(如iframe onload)?

This doesn't work in any browser I've tried it with (IE, Firefox, Chrome). How can I detect when a page is loaded in the window (like an iframe onload)?

推荐答案

如果弹出文档来自不同的域,这是根本不可能的。

If the pop-up's document is from a different domain, this is simply not possible.

2015年4月更新:我错了:如果您拥有这两个域,可以使用 window.postMessage 消息事件几乎所有的浏览器今天是相关的。

Update April 2015: I was wrong about this: if you own both domains, you can use window.postMessage and the message event in pretty much all browsers that are relevant today.

如果没有,那么仍然没有办法在没有来自被加载的文档的帮助的情况下使这个工作跨浏览器进入弹出窗口。您需要能够检测到弹出窗口一旦加载就发生变化,这可能是弹出页面中的JavaScript处理它自己的 load 时设置的变量c $ c>事件,或者如果你有一些控制权,你可以添加一个调用函数在开罐器。

If not, there's still no way you'll be able to make this work cross-browser without some help from the document being loaded into the pop-up. You need to be able to detect a change in the pop-up that occurs once it has loaded, which could be a variable that JavaScript in the pop-up page sets when it handles its own load event, or if you have some control of it you could add a call to a function in the opener.

这篇关于检测用window.open打开的窗口的onload事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆