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.

SettingValueDescription
fullscreen"yes"or "no"Whether to use full to show the content. Internet Explorer only.
heightNumberThe height of the new window. This cannot be less than 100.
leftNumberThe 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".
topNumberThe top coordinate of the new window. This cannot be a negative number.
widthNumberThe 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
Home 
  JavaScript Book 
    DOM  

Window:
  1. The Window Object
  2. The Window Events
  3. window.alert() or alert()
  4. window.close()
  5. window.confirm() or confirm()
  6. window.find() displays find dialog
  7. window's outer width and height, inner height and width
  8. window.location
  9. window.moveBy(distance, distance)
  10. window.moveTo(x,y) moves the window to the upper-left coordinate
  11. window.open()
  12. window.print()
  13. window.prompt() and prompt()
  14. window.resizeTo(x,y) and window.resizeBy(xDelta,yDelta)
  15. window.scrollTo(x,y)
  16. window.screenLeft, window.screenX, window.screenTop, window.screenY
  17. window.setInterval() or setInterval()
  18. window.setTimeout() or setTimeout()
  19. Pop-up Blockers