The top property should consistently refer to the window at the top of the hierarchy. The window property refers to the current window.
You can test attributes of the top window against attributes of the current window to see if your script is running in a correctly framed context. This may be useful if you have a frame dependent page that may have been linked to by a search engine. You can force the page into the correct frame-set if you can detect that it has been invoked outside of it.
if(top != window)
{
// The window is in a frameset
}
This property will contain a meaningful value regardless of whether the window is in a frame or not.
If the pages are known to come from the same server, you may want to check the window.location.href property against the top.location.href property. However, this may cause problems if the pages come from different servers and cause the script to throw a security related exception.
Prev | Home | Next |
Window.toolbar | Up | Window.window |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |