|
A main use for JavaScript is to manipulate
windows and frames to make your site more easy to navigate through and so forth. A window
object can be handled by a JavaScript object called window ,
wherreas a document object can always be opened by a JavaScript object called document . This part of our tutorial will get you more
familar with JavaScript capabilities with windows and frames. Obviously, you know a browser can open more than one window at once. Each window
is represented by a Window object in JavaScript. Using JavaScript, you can have full
control of opening new windows. The simplest way to open a new window is using open() . This is an important function. It can be used in
several ways. Below is a simple way to open a new window using JavaScript and the open() function:
|
var win1="open(newwindow.html");
function new_win()
|
Then call it in your HTML document like so:
By using a # in the tag, you prevent a page from being
replaced when a link is followed. Now you can open more than 1 window at a time and
specify the size of the window your opening.
|
var win1="open(newwindow.html" "resizable=no,height=500,width=500");
function new_win()
{
var win1="open(newwindow2.html" "resizable=no,height=100,width=100");
}
|
This will open 2 windows; one window smaller then the
other. This is quite simple and can be done for any amount of windows.
The open()
function is very powerful; it provides the new window with a name and a set of window
property options. Please note, the arguments to open()
must be comma-separated, not space separated. In order to pop up windows without a user
clicking (I must warn, can be extremely annoying!) is to not call a function. Just use:
|
variable-name = open("url, "windowname",
"resizeable=no,height=100, width=100");
|
This is usually a bad for 2 major reasons. When the
function ends and the variable goes, you loose track of the new window. It is better to
keep the variable permanent, incase you want to use it again. Also, people do NOT
appreciate unexpected windows popping up all over (ie Geocities, Tripod). |