Javascript examples for Browser Object Model:Window open
The open() method opens a new browser window.
window.open(URL, name, specs, replace)
Parameter | Description |
---|---|
URL | Optional. URL of the page to open. If not specified, about:blank is opened |
name | Optional. Specifies the target attribute or the name of the window. The following values are supported: _blank - URL is loaded into a new window. This is default _parent - URL is loaded into the parent frame _self - URL replaces the current page _top - URL replaces any framesets that may be loaded name - The name of the window |
specs | Optional. A comma-separated list of items, no whitespaces. The following values are supported: |
height=pixels left=pixels menubar=yes|no|1|0 status=yes|no|1|0 titlebar=yes|no|1|0 top=pixels width=pixels | The height of the window. Min. value is 100 The left position of the window. Negative values not allowed Whether or not to display the menu bar Whether or not to add a status bar Whether or not to display the title bar. The top position of the window. The width of the window. Min. value is 100 |
replace | Optional. whether the URL creates a new entry or replaces the current entry in the history. |
A reference to the newly created window, or null if the call failed
The following code shows how to Open "java2s.com" in a new browser window:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <script> function myFunction() {/* ww w .ja v a 2 s. co m*/ var myWindow = window.open("", "myWindow", "width=200,height=100"); myWindow.document.write("<p>This is 'myWindow'</p>"); myWindow.opener.document.write("<p>This is the source window!</p>"); } </script> </body> </html>