Window open () method
Definition and Usage
open () method is used to open a new browser window or find a named window.
grammar
window.open(URL,name,specs,replace)
parameter | Explanation | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
URL | Optional. Open URL specified page. If you do not specify a URL, open a new blank window | ||||||||||||||||||||||||||||
name | Optional. Specifies the name of the target attribute or window. It supports the following values:
| ||||||||||||||||||||||||||||
specs | Optional. A comma-separated list of items. It supports the following values:
| ||||||||||||||||||||||||||||
replace | Optional.Specifies specifies the URL is loaded into the window to create a new entry in the browsing history window, or replaces the current entry in the browsing history. It supports the following values:
|
Browser Support
All major browsers support open () method
Examples s
Example 1
Opens in a new browser window www.w3big.com:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function open_win () {
window.open ( "http://www.w3big.com");
}
</ Script>
</ Head>
<Body>
<Form>
<Input type = "button" value = "open window" onclick = "open_win ()">
</ Form>
</ Body>
</ Html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function open_win () {
window.open ( "http://www.w3big.com");
}
</ Script>
</ Head>
<Body>
<Form>
<Input type = "button" value = "open window" onclick = "open_win ()">
</ Form>
</ Body>
</ Html>
try it"
Example 2
The following example opens in a new browser window a blank page:
function openWin () {
myWindow = window.open ( '', '', 'width = 200, height = 100');
myWindow.document.write ( "<p> This is 'my window' </ p>");
myWindow.focus ();
}
myWindow = window.open ( '', '', 'width = 200, height = 100');
myWindow.document.write ( "<p> This is 'my window' </ p>");
myWindow.focus ();
}
try it"
More examples
A new window opens, and control their appearance
Window object