我有一个选择框,调用window.open(url)当一个项目被选中。默认情况下,Firefox将在新选项卡中打开页面。但是,我希望页面在一个新的窗口中打开,而不是一个新的选项卡。

我怎样才能做到呢?


当前回答

你不需要使用height,只要确保你使用_blank,没有它,它会在一个新选项卡中打开。

对于空窗口:

window.open('', '_blank', 'toolbar=0,location=0,menubar=0');

对于特定的URL:

window.open('http://www.google.com', '_blank', 'toolbar=0,location=0,menubar=0');

其他回答

你可以试试下面的函数:

<script type="text/javascript">
function open(url)
{
  var popup = window.open(url, "_blank", "width=200, height=200") ;
  popup.location = URL;
}
</script>

执行的HTML代码:

<a href="#" onclick="open('http://www.google.com')">google search</a>

我可能错了,但据我所知,这是由用户的浏览器首选项控制的,我不相信这可以被重写。

你不需要使用height,只要确保你使用_blank,没有它,它会在一个新选项卡中打开。

对于空窗口:

window.open('', '_blank', 'toolbar=0,location=0,menubar=0');

对于特定的URL:

window.open('http://www.google.com', '_blank', 'toolbar=0,location=0,menubar=0');

关键是参数:

如果你提供参数[Height="", Width=""],那么它将在新窗口中打开。

如果你不提供参数,那么它将在新选项卡中打开。

在Chrome和Firefox中测试

试试这个方法.....

function popitup(url) {
       //alert(url);
       newwindow=window.open("http://www.zeeshanakhter.com","_blank","toolbar=yes,scrollbars=yes, resizable=yes, top=500, left=500, width=400, height=400");
       newwindow.moveTo(350,150);
   if (window.focus) 
          {
             newwindow.focus()
          }
   return false;
  }