Open "www.java2s.com" in a new browser tab:
window.open("https://www.java2s.com");
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from ww w. ja va 2 s . c o m*/ window.open("https://www.java2s.com"); } </script> </body> </html>
The open()
method opens a new browser window, or a new tab, depending on your browser settings and the parameter values.
Use the close()
method to close the window.
open();
Parameter Values
Parameter | Description |
---|---|
URL | Optional. URL of the page to open. If no URL is specified, a new window/tab with about:blank is opened |
name | Optional. target attribute or the name of the window. The following values are supported: _blank - URL is loaded into a new window, or tab. This is default _parent - URL is loaded into the parent frame _self - URL replaces the current page _top - URL replaces any frameset that may be loaded name - The name of the window |
specs | Optional. A comma-separated list of items, no whitespace. The following values are supported: height=pixels The height of the window. Min. value is 100 left=pixels The left position of the window. Negative values not allowed menubar=yes|no|1|0 Whether or not to display the menu bar status=yes|no|1|0 Whether or not to add a status bar titlebar=yes|no|1|0 Whether or not to display the title bar. top=pixels The top position of the window. Negative values not allowed width=pixels The width of the window. Min. value is 100 height=pixels The height of the window. Min. value is 100 left=pixels The left position of the window. Negative values not allowed menubar=yes|no|1|0 Whether or not to display the menu bar status=yes|no|1|0 Whether or not to add a status bar titlebar=yes|no|1|0 Whether or not to display the title bar. top=pixels The top position of the window. Negative values not allowed width=pixels The width of the window. Min. value is 100 |
replace | Optional. Specifies whether the URL creates a new entry or replaces the current entry in the history list. The following values are supported: true - URL replaces the current document in the history list false - URL creates a new entry in the history list |
The open()
method return a reference to the newly created window, or null if the call failed.