Java Reference
In-Depth Information
This HTML adds a frame with the name myIFrame to the page, which loads the child_frame.htm
fi le. As you may guess, this simplicity carries over to your JavaScript. Accessing the iframe's document
object of the page loaded in it is straightforward. For example:
window.myIFrame.document.bgColor = “red”;
As you can see, it's very similar to conventional frames within a frameset (you can also use the frames
collection like window.frames[“myIFrame”]). Accessing the parent window from within the iframe
is also familiar; use the parent property. For example:
window.parent.document.bgColor = “yellow”;
Opening New Windows
So far in this chapter, you have been looking at frames and scripting between them. In this section,
you'll change direction slightly and look at how you can open up additional browser windows.
Why would you want to bother opening up new windows? Well, they can be useful in all sorts of dif-
ferent situations, such as the following:
You might want a page of links to web sites, in which clicking a link opens up a new window
with that web site in it.
Additional windows can be useful for displaying information. For example, if you had a page
with products on it, the user could click a product image to bring up a new small window list-
ing the details of that product. This can be less intrusive than navigating the existing window to
a new page with product details, and then requiring the user to click Back to return to the list of
products. You'll be creating an example demonstrating this later in this chapter.
Dialog windows can be very useful for obtaining information from users, although overuse may
annoy them.
The latest versions of all modern browsers include a pop-up blocking feature. By default, new windows
created automatically when a page loads are usually blocked. However, windows that open only when
the user must perform an action, for example clicking a link or button, are not normally blocked by
default, but the user may change the browser settings to block them.
Opening a New Browser Window
The window object has an open() method, which opens up a new window. It accepts three parameters,
although the third is optional, and it returns a reference to the window object of the new browser window.
The fi rst parameter of the open() method is the URL of the page that you want to open in the new win-
dow. However, you can pass an empty string for this parameter and get a blank page and then use the
document.write() method to insert HTML into the new window dynamically. You'll see an example
of this later in the chapter.
Search WWH ::




Custom Search