jQuery:如何检查新打开的窗口是否已完全加载? /窗口加载外部页面(例如www.yahoo.com) [英] Jquery: how to check if a newly opened window has been fully loaded? / window loads an external page (like www.yahoo.com)
问题描述
以下内容无效,为什么?
the following doesn't work , why ?
var myWindow=null;
myWindow = window.open(targetUrlVar,"_blank","resizable=yes");
$(myWindow).load(function(){
alert('hello');
});
尽管MyWindow是Window的引用,但不检查它是否已完全加载.我以为$(window).load(...)
在这里适用于窗口"被"MyWindow"替换的情况.
Though MyWindow is a Window reference, no check is performed to see whether or not it has been fully loaded. i thought $(window).load(...)
would work here for "window " being replaced by "MyWindow".
以下作品:
$(myWindow).load(function(){
alert('hello');
});
对于targetUrlVar是内部资源(例如属于我的域的页面),它可以工作.
但是一旦我想将.load()
或myWindow.onload()
与targetUrlVar
用作外部页面(例如www.yahoo.com或www.google.com)一起使用时,它将不再起作用. .
没有警报显示.
for targetUrlVar being an internal resource (like a page belonging to my domain) it works..
but as soon as i wanted to used the .load()
or myWindow.onload()
with a targetUrlVar
being an external page (such as www.yahoo.com or www.google.com ), it doesn't work any more...
No alert is displayed..
我需要您的帮助...谢谢大家
i need you help... thank you everyone
推荐答案
如果无论子窗口DOM的状态如何,都希望在子窗口打开时触发警报,则此方法应该起作用.我还提供了一种检验此假设的方法.
If you want to trigger the alert when the child window is open regardless of the state of the child window's DOM then this should work. I also provided a way to test this assumption.
创建具有以下内容的测试PHP脚本(或类似的脚本语言):
Create a test PHP script (or similar scripting language) with the following content:
<html>
<head><title>test</title></head>
<body>
<?php sleep(5); // Sleep to delay DOM from loading ?>
Done sleeping...
</body>
</html>
然后使用以下javascript将此测试页称为您的子窗口:
Then call this test page as your child window usingthe following javascript:
win = window.open('test.php', 'test', 'width=300, height=400, x=800');
win.focus();
$(win.document).ready(function() {
alert('Window is open');
});
您会注意到子窗口中出现"Done sleep ..."之前,父窗口中的alert()已触发.
You'll notice that the alert() from the parent window fires before you see "Done sleeping..." appear in the child window.
这篇关于jQuery:如何检查新打开的窗口是否已完全加载? /窗口加载外部页面(例如www.yahoo.com)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!