Jquery:如何检查新打开的窗口是否已完全加载? / window 加载外部页面(如 www.yahoo.com)
以下不起作用,为什么?
var myWindow=null;
myWindow = window.open(targetUrlVar,"_blank","resizable=yes");
$(myWindow).load(function(){
alert('hello');
});
尽管 MyWindow 是一个 Window 引用,但不会执行任何检查来查看它是否已完全加载。我认为 $(window).load(...)
可以在这里工作,因为“window”被“MyWindow”替换。
以下有效:
$(myWindow).load(function(){
alert('hello');
});
对于 targetUrlVar 作为内部资源(如属于我的域的页面),它有效。 但一旦我想使用 .load()
或 myWindow.onload()
以及 targetUrlVar
作为外部页面(例如www.yahoo.com 或 www.google.com ),它不再起作用了...... 没有显示警报..
我需要你的帮助...谢谢大家
the following doesn't work , why ?
var myWindow=null;
myWindow = window.open(targetUrlVar,"_blank","resizable=yes");
$(myWindow).load(function(){
alert('hello');
});
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".
the following works:
$(myWindow).load(function(){
alert('hello');
});
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想在子窗口打开时触发警报,无论子窗口 DOM 的状态如何,那么这应该可行。我还提供了一种方法来测试这个假设。
使用以下内容创建一个测试 PHP 脚本(或类似的脚本语言):
然后使用以下 javascript 将此测试页调用为子窗口:
您会注意到,在看到“Done sleep. ..”出现在子窗口中。
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.
Create a test PHP script (or similar scripting language) with the following content:
Then call this test page as your child window usingthe following javascript:
You'll notice that the alert() from the parent window fires before you see "Done sleeping..." appear in the child window.
希望这有帮助。
Hope this helps.
我发现这个问题有点老了。
然而,亚瑟表示,
我认为问题可能是由于 targetUrlVar 是外部的;该警报可能会被阻止以防止跨站点脚本(又名 XSS)。
I see this question is somewhat old.
However, arthur stated,
I think that the issue may be due to the targetUrlVar being external; the alert may be blocked to prevent cross-site scripting (aka XSS).