IE7 window.open当.focus返回null时 [英] IE7 window.open when .focus return null

查看:106
本文介绍了IE7 window.open当.focus返回null时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做这样的事情

I'm trying to do something like this

win = null;
win = window.open('/url/to/link','tab');
win.focus();

但是在IE7中,它在win.focus();行返回我.赢得的错误为空.

but in IE7 it returns me at the line of win.focus(); the error that win is null.

我该如何解决?

提前谢谢!

推荐答案

您可以尝试稍加延迟以确保窗口已打开

You can try adding a slight delay to make sure that the window is open

//win = null;  <--useless
win = window.open('/url/to/link','tab');
if(win)window.focus();
else{
    var timer = window.setTimeout( function(){ if(win)win.focus(); }, 100 );
}

这一天,大多数人都避免弹出窗口并使用模式图层.

This day in age, most people avoid pop up windows and use modal layers.

这篇关于IE7 window.open当.focus返回null时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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