【问题标题】:window.open only in Firefox?window.open 仅在 Firefox 中?
【发布时间】:2012-07-25 13:19:08
【问题描述】:

对不起,如果这是一个重复的问题!

我有以下 Javascript 可以在 Firefox 中正常工作并生成一个弹出窗口。然而在 IE 9 中它什么都不做,而在 Chrome 中它就像一个链接并改变当前页面!

任何建议表示赞赏!

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

提前致谢。

【问题讨论】:

  • 你试过用“_blank”作为名字吗?
  • 毫无乐趣地尝试了 _blank :(
  • @jbabey:对不起,伙计,但 - 也适用于名称(离开 IE);窗口将打开。
  • @jbabey 你说的是(-)而不是空格..记住

标签: javascript html


【解决方案1】:

这是一个工作示例

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.

【讨论】:

    【解决方案2】:

    您是否正确创建了变量?

    这段代码对我有用:

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

    【讨论】:

      【解决方案3】:

      您在哪里拨打window.open 的电话?如果在页面加载期间作为其弹出窗口阻止程序的一部分进行调用,IE9 将阻止调用。 Chrome 做了类似的事情,但将新窗口重定向到主选项卡(因此,让用户处于控制之中)。至于 Firefox……检查你的 FF 弹出窗口拦截器设置。

      【讨论】:

      • 它在订单系统中,当用户单击更新状态时,他们会得到(无论如何在 Firefox 中!)一个带有下拉多选(即已发货、已完成等)和一个提交按钮的弹出窗口.因此弹出是由用户触发的
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多