window.open仅在Firefox中打开

window.open only in Firefox?

本文关键字:Firefox open 仅在 window      更新时间:2024-02-07

如果这是一个重复的问题,很抱歉!

我有下面的Javascript,它在Firefox中运行良好,并产生一个弹出窗口。然而,在IE 9中,它什么都不做,在Chrome中,它就像一个链接,可以更改当前页面!

非常感谢您的建议!

window.open(page,name,'width='+width+', height='+height+',location=yes,menubar=no,resizable=no,toolbar=no,scrollbars=yes');

提前谢谢。

这是的一个工作示例

JS

function openWindow()
{
    var width=668;
    var height=548;
    var page="http://google.com";
    window.open(page, "awindow", "width="+width+",height="+height+",location=yes,scrollbars=yes, resizable=yes");
}

HTML

<a href="javascript:openWindow()">Open</a>​

演示

您是否正确创建了变量?

这个代码对我有效:

var page = 'page.php';
var name = 'pagename';
var width = 200;
var height = 100;
window.open(page,name,'width='+width+', height='+height+',location=yes,menubar=no,resizable=no,toolbar=no,scrollbars=yes');

编辑

在我的网络应用程序中,我使用以下功能打开窗口。它应该适用于所有浏览器。

function wopen(url, name, w, h, scrollb) {
    scrollb = typeof(scrollb) != 'undefined' ? scrollb : 'no';
    w += 32;
    h += 96;
    wleft = (screen.width - w) / 2;
    wtop = (screen.height - h) / 2;
    var win = window.open(url, name,
    'width=' + w + ', height=' + h + ', ' + 'left=' + wleft + ', top=' + wtop + ', ' +
    'location=no, menubar=no, ' +
    'status=no, toolbar=no, scrollbars=' + scrollb + ', resizable=yes');
    // Just in case width and height are ignored
    win.resizeTo(w, h);
    // Just in case left and top are ignored
    win.moveTo(wleft, wtop);
    win.focus();
}

您在哪里调用window.open?IE9将阻止调用,如果它们是在页面加载过程中作为弹出窗口阻止程序的一部分进行的。Chrome做了类似的事情,但将新窗口重定向到主选项卡(从而让用户控制)。至于Firefox。。。检查您的FF弹出窗口阻止程序设置。