window.open只在Firefox?

时间:2012-07-25 13:19:09

标签: javascript html

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

我有以下Javascript在Firefox中工作正常并生成一个弹出窗口。在IE 9中,它根本不做任何事情,在Chrome中它就像链接一样工作并更改当前页面!

任何建议表示赞赏!

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

提前致谢。

3 个答案:

答案 0 :(得分:2)

这是一个有效的例子

<强> 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>​

DEMO.

答案 1 :(得分:1)

您是否正确创建了变量?

此代码对我有用:

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');

修改

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

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();
}

答案 2 :(得分:0)

你在哪里拨打window.open的电话? IE9将阻止调用,如果它们是在页面加载期间作为其弹出窗口阻止程序的一部分。 Chrome做了类似的事情,但将新窗口重定向到主标签(从而使用户处于控制之下)。至于Firefox ...检查你的FF弹出窗口拦截器设置。

相关问题