window.open()
The window.open() method can navigate to a particular URL and open a new browser window.
This method accepts four arguments:
- URL to load,
- window target,
- a string of features,
- a Boolean value to tell whether to take the place of the currently loaded page in the browser history.
If the second argument is the name of an existing window or frame, then the URL is loaded into the window or frame with that name.
//same as <a href="http://www.java2s.com" target="topFrame"></a>
window.open("http://www.java2s.com/", "topFrame");
The second argument may be any of the special window names:
- _self
- _parent
- _top
- _blank.
The third argument is a comma-delimited string indicating display information for the new window. The following table describes the various options.
Setting | Value | Description |
---|---|---|
fullscreen | "yes"or "no" | Whether to use full to show the content. Internet Explorer only. |
height | Number | The height of the new window. This cannot be less than 100. |
left | Number | The left coordinate of the new window. This cannot be a negative number. |
location | "yes"or "no" | Whether to display the location bar. |
menubar | "yes"or "no" | Whether to show the menu bar. The default is "no". |
resizable | "yes"or "no" | Is the new window going to resizable. The default is "no". |
scrollbars | "yes"or "no" | If the new window can scroll. The default is "no". |
status | "yes"or "no" | If the new window can have status bar. |
toolbar | "yes"or "no" | If the window can have the toolbar. The default is "no". |
top | Number | The top coordinate of the new window. This cannot be a negative number. |
width | Number | The width of the new window. This cannot be less than 100. |
Any or all of these settings may be specified as a comma-delimited set of name-value pairs. The name-value pairs are indicated by an equal sign. No white space is allowed in the feature string.
window.open("http://www.java2s.com/","java2sWindow","height=400,width=400,top=10,left=10,resizable=yes");
The window.open() method returns a reference to the newly created window. This object can be used to manipulate the newly opened window:
var java2sWin =window.open("http://www.java2s.com/","myWindow");
java2sWin.resizeTo(500, 500);
java2sWin.moveTo(100, 100);
It's possible to close the newly opened window by calling the close() method as follows:
java2sWin.close();
This method works only for pop-up windows created by window.open().
The newly created window object has a reference back to the window that opened it via the opener property. For example:
var java2sWin =window.open("http://www.java2s.com/","java2sWindow");
document.writeln(java2sWin.opener == window); //true
JavaScript Book
DOM
- The Window Object
- The Window Events
- window.alert() or alert()
- window.close()
- window.confirm() or confirm()
- window.find() displays find dialog
- window's outer width and height, inner height and width
- window.location
- window.moveBy(distance, distance)
- window.moveTo(x,y) moves the window to the upper-left coordinate
- window.open()
- window.print()
- window.prompt() and prompt()
- window.resizeTo(x,y) and window.resizeBy(xDelta,yDelta)
- window.scrollTo(x,y)
- window.screenLeft, window.screenX, window.screenTop, window.screenY
- window.setInterval() or setInterval()
- window.setTimeout() or setTimeout()
- Pop-up Blockers