On-line Guides

How To Guides






The JavaScript FAQ
Prev Home Next

Is my page framed?

Question: Is my page framed (loaded in a frameset) or is it in the browser's top-level window?

Answer: To test whether your page is in a frameset, you can use this conditional operator:

if (self.location!=top.location) // if yes, you're framed
if (self.location==top.location) // here you aren't framed
Example. Let's assume that your site uses frames to provide some navigation functionality (like this site does). Assume that your top-level frameset is in the file /index.htm. What if a user arrives to some of your pages without frames? (This might happen if the user arrived e.g. from a search engine.) For such users, you may want to display an additional hyperlink to your top-level frameset - only if your page is not in the frameset yet.
if (self.location==top.location) {
 // The page is not in the frameset index.htm !!! 
 document.write('<p><a href="/index.htm">Home page</a>')
}
A similar code is used on this page. If you of your browser, you'll see an additional hyperlink Table of Contents (at the top of the page, right under the page title). This hyperlink will bring you back to the framed view.

JavaScripter.net. Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next


Mirrored with kind permission of Alexei Kourbatov Design by Interspire

AltStyle によって変換されたページ (->オリジナル) /