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)

查看:17
本文介绍了Jquery:如何检查新打开的窗口是否已完全加载?/窗口加载外部页面(如 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(...) 在这里可以用于将window"替换为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');
});

在您看到子窗口中出现完成睡眠..."之前,您会注意到来自父窗口的 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屋!

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