JavaScript open in a new window, not tab

2022-08-29 23:30:54

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

How can I accomplish this?


答案 1

Specify window "features" to the call:open

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.


答案 2

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

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