Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Sep 28, 1998

Using JavaScript to Check if Frameset is Loaded

You can use JavaScript at the top of an HTML document to detect if a frameset is loaded and if not, load the frameset. If a window's top property points to the window itself then that frame is the main frameset or document:
 
<HTML>
<HEAD>
<SCRIPT Language="JavaScript">
if (window.top == window) {
  window.top.location = "frame.htm";
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FF0000">
<H1>This is document #1</H1>
</BODY>
</HTML>
If that's true in this case then the user has somehow bypassed the frameset that sets up your site's navigational elements. Simply changing the window's location property to the URL of the appropriate frameset HTML sets everything right. Also, this is a good way to check if your page is being displayed as part of someone else's frameset and break out of it if necessary:
 
<HTML>
<HEAD>
<SCRIPT Language="JavaScript">
if (window.top != window) {
  window.top.location = window.location;
}
</SCRIPT>
</HEAD>
<FRAMESET COLS="30%,70%">
  <FRAME NAME="doc1" SRC="doc1.htm">
  <FRAME NAME="doc2" SRC="doc2.htm">
</FRAMESET>
</HTML>
Boris Feldman
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date