JavaScript open in a new window, not tab

前端 未结 15 1285
余生分开走
余生分开走 2020-11-21 22:18

I have a select box that calls window.open(url) when an item is selected. Firefox will open the page in a new tab by default. However, I would like the page t

相关标签:
15条回答
  • 2020-11-21 23:09

    You don't need to use height, just make sure you use _blank, Without it, it opens in a new tab.

    For a empty window:

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

    For a specific URL:

    window.open('http://www.google.com', '_blank', 'toolbar=0,location=0,menubar=0');
    
    0 讨论(0)
  • 2020-11-21 23:10

    For me the solution was to have

    "location=0"
    

    in the 3rd parameter. Tested on latest FF/Chrome and an old version of IE11

    Full method call I use is below (As I like to use a variable width):

    window.open(url, "window" + id, 'toolbar=0,location=0,scrollbars=1,statusbar=1,menubar=0,resizable=1,width=' + width + ',height=800,left=100,top=50');
    
    0 讨论(0)
  • 2020-11-21 23:11

    Specify window "features" to the open call:

    window.open(url, windowName, "height=200,width=200");
    

    When you specify a width/height, it will open it in a new window instead of a tab.

    See https://developer.mozilla.org/en-US/docs/Web/API/Window.open#Position_and_size_features for all the possible features.

    0 讨论(0)
提交回复
热议问题