Window open() Method

JavaScript can be utilized to initiate the launch of a fresh browser window. The window.open() method serves the purpose of enabling the opening of a new browser window while retaining the current page.

This functionality proves advantageous in scenarios where the display of popup advertisements or instructional materials is required without interrupting the current window. For the purpose of unveiling a new browser window, one should employ the window.open() method.

Syntax
window.open( sURL, windowName, "attributes");
run this source code Browser View


Source
<html> <head> <script type="text/javascript"> function newWindow() { var newWindow = window.open("", "", "width=300, height=300"); } </script> </head> <body> <form> <button onclick="newWindow()">Click here to open New Window</button> </form> </body> </html>

In the aforementioned code snippet, the resulting value, which is stored within the variable newWindow, represents the reference to the newly created window. This reference can be utilized subsequently, such as for closing the window (newWindow.close()), bringing focus to the window (newWindow.focus()), or executing additional window manipulations.

The important Parameter of window.open() method are url, name, left, top, height and width. The other parameters are toolbar, menubar, scrollbars and resizable.

run this source code Browser View


Source
<html> <head> <script type="text/javascript"> function newWindow() { var newWindow = window.open("https://net-informations.com", "_blank", "top=100, left=100, width=800, height=500, menubar=yes,toolbar=yes, scrollbars=yes, resizable=yes"); } </script> </head> <body> <form> <button onclick="newWindow()">Click here to open New Window</button> </form> </body> </html>

Typically, when opening a new popup window in JavaScript, only the initial three arguments are commonly employed. It is crucial to acknowledge that the initiation of the new window can be hindered if JavaScript has been disabled within the user's browser, as a result of diverse browser policies and user preferences that may impede the opening of popup windows. Additionally, in the present era, the majority of browsers are equipped with integrated pop-up blocking mechanisms intended to thwart any misuse of this technique for marketing purposes.

Conclusion

During the early stages of the web, Popup windows were excessively utilized and subjected to exploitation by numerous websites. Consequently, subsequent versions of web browsers incorporated measures to block such popup windows. Over time, the prevalence of popup windows has diminished significantly. Presently, automatically triggering popup windows is widely regarded as a highly unfavorable practice in the web development community.