Home >Web Front-end >JS Tutorial >How to Force `window.open()` to Open in a New Window, Not a Tab?
Opening Windows, Not Tabs, with JavaScript
Problem:
When using JavaScript's window.open() method to navigate from a select box, Firefox defaults to opening the page in a new tab. The desired behavior, however, is for the page to open in a new window.
Solution:
To override Firefox's default behavior, specify the "features" of the new window in the window.open() call. The following code achieves the desired result:
window.open(url, windowName, "height=200,width=200");
Explanation:
By specifying a height and width for the window, you force it to open as a new window rather than a tab.
Additional Information:
For a comprehensive list of all the possible "features" you can specify to control the appearance and behavior of the new window, refer to the following Mozilla documentation: https://developer.mozilla.org/en-US/docs/Web/API/Window.open#Position_and_size_features
The above is the detailed content of How to Force `window.open()` to Open in a New Window, Not a Tab?. For more information, please follow other related articles on the PHP Chinese website!