Home >Web Front-end >JS Tutorial >How to Force `window.open()` to Open in a New Window, Not a Tab?

How to Force `window.open()` to Open in a New Window, Not a Tab?

Linda Hamilton
Linda HamiltonOriginal
2024-12-14 14:50:18823browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn