Index
 

 

 

Don't get framed in a frame.


A lot of web sites make use of frames. If you do this yourself, you'll want your frameset to be the "top-level" frameset. Even when you don't use frames yourself, you probably don't like your page to end-up inside the frameset of another web site. You can never be 100 percent sure that someone making a link to your page from a "framed" page, makes this link with the target "_top". This may cause your page (or frameset) to be displayed inside the frame from which it was called. To make sure this does not happen, you can add a small piece of JavaScript in the head of your page (or frameset), so your page does not get "framed" in another frame. Below is this piece of JavaScript.

<script language="JavaScript">
<!-- 
    if (top.frames.length != 0)
    top.location = self.document.location;
//-->
</script>
Example.   What this little script does is, before it's own frameset is created, or the page is showed, it checks the length of the array of frames. If this is not 0 (zero), this means that frames already exist in the browser window, and our own frameset or page is likely to get "framed" in a frame. If this is the case, it changes top.location (the URL location of the browser screen) to its own URL (self.document.location )

If this piece of script is used in a frameset, it must reside between the <HEAD> and the </HEAD> tags.

If you want to know more about frames and how they work, you can find this information in the Frames Tutor.

 



Top
Last change on November 8th 1999.