This article gives you the basics of designing, opening, and closing browser windows using Java Script. In future articles, I will show you how to do all kinds of annoying things with windows using Java Script.
Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022

Easy Java Script Windows

Opening a browser window with JavaScript is extremely easy. If you don't believe me, type this text into your web page.


When you open your web page, a popup window named about:blank will appear.

In the code above we have used the fact that the browser defaults to Java Script. Proper coding would have specified the script language and assigned the window to a variable so that we could use that variable to control the window after we create it. The example below shows the proper code to create a window and load a web page named mypage.htm into the window.

<script language="JavaScript">
var myPopUp ="mypage.htm","pop_window");

Of course, you don't have to load a local web page into the window, you can put any URL in the first argument of the function. Note the second argument of the function, "pop_window". This gives the window a name that you can use to load a different page into the window, as shown below.

<a href="mypage2.htm" target="pop_window">Link Text</a>

You can add a third argument, called the "features list", to the function. Below is a list of the features that you can specify.

leftlocation of the left border of the window in pixels from the left side of the screen
toplocation of the top border of the window in pixels from the top of the screen
widthwidth of the window in pixels
heightheight of the window in pixels
menubarspecifies the menu bar
toolbarspecifies the tool bar
locationspecifies the address bar
scrollbarsspecifies scrollbars
statusspecifies the status bar
resizespecifies whether the window can be resized by the user

Assigning a feature the value 1 provides the feature. Assigning a feature the value 0 prevents the feature. The example below creates a window with a menu bar and address bar, but no tool bar. Note that the feature specifications are separated by commas, and you can put them in any order.

<script language="JavaScript">
var myPopUp ="mypage.htm", "pop_window", "menubar=1, location=1, toolbar=0"); </script>

What happens if you omit the specification of a feature? That depends on the browser version used to view the page. In some browsers, features not specified appear by default. In some browsers features not specified are not provided by default. To get reliable results, you should always specify all the features.

If you like to reuse code, you can specify the features list in a string variable and then use that variable name as the features list argument in the function. This will prevent you from having to memorize the features list.

<script language="JavaScript">
var features = "left=100, top=100, width=256, height=256, menubar=1, toolbar=0, location=0, scrollbars=0, status=0"; var myPopUp ="mypage.htm", "pop_window",features); </script>

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro

Web Design Sections

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2016 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268