Java Reference
In-Depth Information
The
parent property returns the window object that contains the current window object, which
will be the page containing the frameset that created the window. The top property returns the
window object of the window containing all the other frames.
Each frame in a frameset can be accessed through three methods. One is to use the name of the
frame. The second is to use the frames collection and specify the index of the frame. The third
way is to access the frame by its name in the frames collection — for example, parent.frames
.frameName . This the safest way, because it avoids any collision with global variables.
If the frame you want to access is defi ned in another window, you need the
parent or top
property to get a reference to the window object defi ning that frame, and then you must specify
the name or position in the frames collection.
You then looked at how you can open new, additional browser windows using script.
Using the
window object's open() method, you can open new windows. The URL of the page
you want to open is passed as the fi rst parameter; the name of the new window is passed as the
second parameter; the optional third parameter enables you to defi ne what features the new
window will have.
The
window.open() method returns a value, which is a reference to the window object of the
new window. Using this reference, you can access the document, script, and methods of that
window, much as you do with frames. You need to make sure that the reference is stored inside
a variable if you want to do this.
To close a window, you simply use the
window.close() method. To check if a window is closed,
you use the closed property of the window object, which returns true if it's closed and false if
it's still open.
For a newly opened
window object to access the window that opened it, you need to use the
window.opener property. Like window.parent for frames, this gives a reference to the window
object that opened the new one and enables you to access the window object and its properties for
that window.
After a window is opened, you can resize it using
resizeTo(x,y) and resizeBy(x,y), and
move it using moveTo(x,y) and moveBy(x,y).
You also looked briefl y at security restrictions for windows and frames that are not of the same origin.
By “not of the same origin,” you're referring to a situation in which the document in one frame is hosted
on one server and the document in the other is hosted on a different server. In this situation, very severe
restrictions apply, which limit the extent of scripting between frames or windows.
In the next chapter, you look at advanced string manipulation.
Exercise Questions
Suggested solutions to these questions can be found in Appendix A.
1.
In the previous chapter's exercise questions, you created a form that allowed the user to pick
a computer system. They could view the details of their system and its total cost by clicking a
button that wrote the details to a textarea. Change the example so it's a frames-based web
Search WWH ::




Custom Search