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!

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

[About BTH]  [User Agreement]  [Privacy Policy]  [Site Map]  [Contact Form]  [Advertise on BTH]  [News Feed]

Google
Web
This Site

Easy Java Script Windows

<script>open()</script>

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 = window.open("mypage.htm","pop_window");
</script>

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 window.open function. Note the second argument of the window.open 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 window.open 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 = window.open("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 window.open 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 = window.open("mypage.htm", "pop_window",features); </script>

Web Design Sections

RSS Feed RSS Feed

Easy Java Script Code
Easy Java Script Windows
Easy Rollovers
Easy Picture Transition Effects
Easy Moving Popup Code
Easy Slide Show Code
Easy Slide Show Code With Linked Slides
Slide Show with Different Size Images
Easy Picture Zoom Code
Easy Picture Panning Code
Easy Java Script Animation
Easy JavaScript Picture Selector Code
Easy Animated Banners with Java Script
Easy Java Script Form Validation
Easy Drag n Drop Code
Easy Graph Generating Code
Easy Code to Sort a Table by Column
Easy Fading Text Banner Code
Easy Expanding Banner Code
Calendars for Your Website
Date Picker For Your Web Site
Calculators For Your Web Site
Loan Payment Calculator
Length Units Converter
Body Mass Index
Fahrenheit to Celsius Converter
Decimal to Hexidecimal Converter
Easy Code for Screen Tape Adding Machine
Code for Java Script Circle⁄Sphere Calculator
Round a Float to 4 Digits to the Right of the Decimal Point
Make Your Own Graphical Digital Clock
Let Your Web site Visitors Set Font Size
How to Disable the Browser Back Button
Add More Bang to Your Content With Keyword Popup Menus
Put a Music Off Switch on Your Webpage
Java Script Random Password Generator
Password Protection Using Java Script
Replace Drop-down with Drag-and-drop
Submit Forms Without CGI
Code for a Less annoying Popup Window
Using the Java Script Array Object
Using the Java Script Date Object
Java Script Message Boxes
How to Shuffle the Deck With Java Script
Web Site Menus : Which Section Am I In?
How Far Did the User Scroll?
Where Did the User Click?
Four Ways to Use Java Script Event Handlers
Create Your Own Database Using Only Notepad : CDV

[Site User Agreement]  [Advertise on This site]  [Search This Site]  [Contact Form]
Copyright©2001-2007 Bucaro TecHelp P.O.Box 18952 Fountain Hills, AZ 85269