Javascript window.open在Win7 x64上的32位IE8中返回null

Bar*_*ett 8 javascript internet-explorer internet-explorer-8 windows-7

我已阅读有关此主题的相关问题,但尚未找到解决此问题的方法.我有一个简单的javascript函数,当单击一个链接时调用window.open:

var newwindow;
function pop(url)
{
    newwindow=window.open(url,'','height=500,width=532');
    if (window.focus) {newwindow.focus();}
}
Run Code Online (Sandbox Code Playgroud)

这在Chrome,Firefox上工作正常,甚至在64位IE 8中工作.但是,当我在32位IE 8中尝试这个时,我得到一个错误,'newwindow'为null或不是对象.

有关为什么会在32位IE 8中出现这种情况的任何想法?

我的预感是它与Windows 7中的UAC相关(我正在运行Win 7 x64),但即使关闭保护模式并运行兼容性视图,我也会收到错误.

我也想知道为什么Windows 7 x64同时配备32位和64位版本的IE 8,以及为什么32位版本固定在我的任务栏上......

Jim*_*son 10

如果网址超出当前域,则Internet Explorer似乎返回null.您可以先打开一个空页面然后将窗口导航到实际的URL来解决它:

var newwindow;
function pop(url)
{
    newwindow=window.open('','','height=500,width=532');
    newwindow.location = url;

    if (window.focus) {newwindow.focus();}
}
Run Code Online (Sandbox Code Playgroud)

  • 这很有效.但是,一旦您使用位置网址设置,新窗口就会刷新,因此window.closed属性变为"true". (3认同)