Window open() Method

You can use JavaScript to launch a new window. The window.open() method, which allows you to open up new browser window without navigating away from the current page. It is useful when you need to display some popup advertisement or the instructions without navigating away from the current window. To open a new browser window, use 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 above code, the return value , stored in the variable newWindow, is the reference to your new window. You can use this reference later, for example, to close this window (newWindow.close()), give focus to the window (newWindow.focus()) or perform other 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>
Normally only the first three arguments are used to open a new popup window in Javascript. It is important to note that the new window will not open if the user disabled the JavaScript in the browser, because various browser policies and user settings may prevent you from opening a popup window. Moreover now a days most browsers have a built in pop-up blocking software for blocking to abuse of the technique for marketing purposes. Such types of Popup windows were overused and exploited by many websites during the earlier days of the web. This resulted in the later versions of browsers blocking popup windows . Eventually, popup windows became almost extinct now. Automatically opening popup windows is considered a very bad practice nowadays.