Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




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 open this page in the top-level window 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. Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next

  Mirrored with kind permission of Alexei Kourbatov Design by Interspire