1. Technology

Your suggestion is on its way!

An email with a link to:

http://javascript.about.com/library/blpopup10.htm

was emailed to:

Thanks for sharing About.com with others!

window.open Reference

The window.open command takes the following format:

var newWin = window.open(url,winName,features,replace);

The parameters passed to the function can be specified as follows:

url

This should be specified as the address of the page to be loaded into the new window. It can be either a relative or absolute address. It can also be left blank if the Javascript following this statement is going to create the content that is to be displayed.

Note that any page specified to be displayed will be loaded asyncronously after the current Javascript finishes running.

winName

This assigns a name to the new window. Any attempt to open a new window with the same name as a window that is already open will result in the open window being reused instead of a new window being opened. Names starting with an underscore have a special meaning and so you should not start the name with an underscore unless you are using one of the special values. The only special value that behaves the same across all browsers is _blank which forces a new window to open without naming it.

Some browsers also support _parent, _self, and _top which will replace a frame or the entire content of the current window instead of opening a new window. In this case the window.open becomes equivalent to parent.location.href, self.location.href, and top.location.href respectively and would be better referenced that way for proper cross browser support.

Older versions of Internet Explorer also supported _media and _search. No current browser supports these options and so their use should be avoided.

features

This parameter defines how you want the new window to appear. This parameter is ignored if an existing window is to be reused. The contents of this parameter is a comma separated list of sub-parameters. Note that many of these options can be disabled in the browser and so they should be considered to be recommendations only. Where a particular sub-parameter allows yes and no as the values that can be set, yes is the default value unless otherwise specified. Some (but not all) browsers allow 1 and 0 to be substituted for yes and no respectively but these should be avoided for proper cross browser support.

  • left specifies the recommended distance from the left of the screen to the left of the new window. If not specified or disabled in the browser then a browser defined offset from the left of the current window will be used.
  • top specifies the recommended distance from the top of the screen to the top of the new window. If not specified or disabled in the browser then a browser defined offset from the top of the current window will be used.
  • width specifies the width of the content area for the new window (including any scrollbars etc). If not specified or disabled then the browser default width will be used. Most browsers have a minimum width that they will allow you to set eg. IE7 will not allow you to set width below 250px.
  • height specifies the height of the content area for the new window (including any scrollbars etc). If not specified or disabled then the browser default width will be used. Most browsers have a minimum height that they will allow you to set eg. IE7 will not allow you to set height below 150px.
  • menubar can be set to yes or no to indicate whether or not the new window should display a menubar. Note that this is a recommendation only as some browsers such as Firefox can disable this to ensure that the menubar will always appear while others such as IE7 will always hide the menubar and this option determines whether the ALT key can be pressed to allow the menubar to be displayed.
  • toolbar can be set to yes or no to indicate whether or not the new window should display a toolbar. Note that this is a recommendation only as some browsers such as Firefox can disable this to ensure that the toolbar will always appear. In IE7 this setting controls whether or not the browser command bar will be displayed.
  • location can be set to yes or no to indicate whether or not the new window should display the location or address bar. Note that this is a recommendation only as some browsers such as Firefox can disable this to ensure that the toolbar will always appear. In IE7 this setting controls whether or not the navigation bar will be displayed as the address bar will always display in that browser.
  • status can be set to yes or no to indicate whether or not the new window should display the status bar. Note that this is a recommendation only as most browsers either force all windows to have a status bar or allow the user to choose.
  • resizable can be set to yes or no to indicate whether or not the new window can be resized. Note that this is a recommendation only as many browsers do not allow you to disable resizing of windows. Setting this to no will disable tabs in IE7.
  • scrollbars can be set to yes or no to indicate whether or not the new window should display scrollbars if required. Note that this is a recommendation only as some browsers such as Firefox can disable this to ensure that the scrollbars can always appear.

There are a number of options that are browser specific. The following only apply to the specified browsers.

  • outerWidth in Firefox, Mozilla, and Netscape defines the overall widthf the new window ratner than just the content area.
  • outerHeight in Firefox, Mozilla, and Netscape defines the overall height of the new window ratner than just the content area.
  • innerWidth in Firefox, Mozilla, and Netscape same as width.
  • outerHeight in Firefox, Mozilla, and Netscape same as height.
  • directories can be set to yes or no to indicate whether or not the new window should displaya personal toolbar, links bar or bookmarks bar depending on the browser. Note that this is a recommendation only as some browsers such as Firefox can disable this to ensure that the appropriate toolbar will always appear. In IE7 this setting is ignored.
  • personalbar can be set to yes or no to indicate whether or not the new window should display the personal toolbar in Mozilla and Firefox only.
  • channelmode can be set to yes or no to indicate whether or not the new window should display in theatre mode in IE only.
  • dependent can be set to yes or no to indicate whether or not the new window should be treated as a dependent of its parent window in Firefox, Mozilla, and Netscape only.
  • dialog can be set to yes or no to indicate whether or not the maximize and minimize buttons will display in the titlebar in Firefox, Mozilla, and Netscape only.
  • minimizable can be set to yes or no to indicate whether or not the minimize buttons will display in the titlebar when dialog=yes in Firefox, Mozilla, and Netscape only.

Firefox, Mozilla, and Netscape also support a number of further options when the specific computer that the browser is running on has UniversalBrowserWrite privilege enabled (eg. when using the browser on an intranet.

  • chrome
  • modal
  • titlebar
  • alwaysRaised
  • alwaysLowered
  • z-lock
  • close

There are also a number of options that were used by older browsers but which are no longer supported. Use of the following should be avoided.

  • screenX
  • screenY
  • fullscreen

replace

This parameter defines how an existing window is to be reused. If true then the new page replaces the current page in the browser history. If false the new page is added to the browser history.

See More About

©2014 About.com. All rights reserved.