聚焦函数在ie8中不起作用

focus function not working in ie8

本文关键字:不起作用 ie8 函数 聚焦      更新时间:2023-09-26

我有一个按钮点击,我在里面放了一个javascript函数来打开一个新窗口,如果我再次点击按钮,同一个窗口会再次刷新并指向它。在firefox和chrome中都可以工作,但在IE中不可以。以下是我尝试的代码

<button onclick="popitup('http://www.google.com');">click</button>
 var newwindow = null;
    function popitup(url) {
        if ((newwindow == null) || (newwindow.closed)) {
            newwindow = window.open(url, 'Buy', 'width=950,height=650,scrollbars=yes,resizable=yes');
            newwindow.focus();
        } else {
            newwindow.location.href = url;
            newwindow.focus();
        }
    }

IE始终返回newwindow==null。。。这就是问题所在。。。有什么解决方案吗?

这对我来说很有用

function windowOpen(url) {
win = window.open(url, 'OpenPage', 'resizable=yes,width=900px,height=620px');
win.focus();
return false;
}

如果不是,请检查您当前的窗口名称是否与newwindow相同。如果是,请使用另一个名称代替newwindow

看看这个:

http://hardlikesoftware.com/projects/IE8FocusTest.html

希望能有所帮助。。