Please note that ExpatTech no longer operates regular office hours, meeting is by appointment only. Please call +36306031104 for details.

ExpatTech Techblog

Nagy Richárd 2008.10.22. 16:35

About the window.open

A lot of times you might run into using this bloody Javascript function. For example when you are replacing target="_blank"-s for the sake of XHTML Strict valid markup (like in Varga Bence's solution - Hungarian). Not like on this blog site, which is HTML 4 Transitional.

Here is the way it is to be used.

window.open(URL, WindowName[, WindowFeatures]);

Not much to say about URL (well, it is a string and it can be blank). You can use WindowName (string) to refer to the window later, also if you call window.open with the same WindowName several times, it will open a new window only for the first time and use the same window for the other calls.

WindowFeatures (string, format: "featurex=n, featurey=m, ...", I only list those that are widely supported):

  • status: displays status bar if 1, does not if 0
  • toolbar: displays browser toolbar (Back, Forward, etc.) if 1, does not if 0
  • location: displays location field (where you enter the URL) if 1, does not if 0
  • menubar: displays browser menu bar if 1, does not if 0
  • directories: displays directory buttons (like annoying What's New and What's Cool) if 1, does not if 0
  • resizable: window is resizable if 1, is not if 0
  • scrollbars: no scrollbars if 0, scrollbars when needed if 1
  • height, width: window dimensions in pixels

The WindowFeatures you do not specify will follow the default browser behavior (if you do not specify any, a standard window is opened).

The function returns an object reference which you can pass to a variable and use it to refer the window later (move the window, write to the window, etc.).

var makimajom=window.open("", "bazevaze");
makimajon.moveTo(100, 50);
makimajom.document.write("mennyafrancba");

Mozilla Reference - here you can also find a nice list about which WindowFeatures are supported in certain browsers

Microsoft Reference