Skip to page content or skip to Accesskey List.
Search evolt.org
evolt.org login: or register

Work

Main Page Content

Breaking out of frames

Rated 3.41 (Ratings: 1) (Add your rating)

Log in to add a comment
(1 comment so far)

Want more?

 
Picture of MartinB

Martin Burns

Member info | Full bio

User since: April 26, 1999

Last login: March 30, 2010

Articles written: 128

Want to make sure your site is not framed by anyone else's? Here's the magic code:

<script language="JavaScript">
<!-- hide
if (window.frames) {
if (parent != self) {
location.href="index.html"
}
}
// unhide -->
</script>

Martin Burns has been doing this stuff since Netscape 1.0 days. Starting with the communication ends that online media support, he moved back through design, HTML and server-side code. Then he got into running the whole show. These days he's working for these people as a Project Manager, and still thinks (nearly 6 years on) it's a hell of a lot better than working for a dot-com. In his Copious Free Time™, he helps out running a Cloth Nappies online store.

Amongst his favourite things is ZopeDrupal, which he uses to run his personal site. He's starting to (re)gain a sneaking regard for ECMAscript since the arrival of unobtrusive scripting.

He's been a member of evolt.org since the very early days, a board member, a president, a writer and even contributed a modest amount of template code for the current site. Above all, he likes evolt.org to do things because it knowingly chooses to do so, rather than randomly stumbling into them. He's also one of the boys and girls who beervolts in the UK, although the arrival of small children in his life have knocked the frequency for 6.

Most likely to ask: Why would a client pay you to do that?

Least likely to ask: Why isn't that navigation frame in Flash?

Submitted by ppk on December 5, 1999 - 07:54.

Here's a collection of possible methods. They were posted by someone else, I added some annotation:
if (window != window.top) top.location.href = location.href;
and
if (location.href != top.location.href) location.href = "index.html"
The safe classical methods.
if (window != top) top.location.replace(document.location.href)
'document.location.href' gives trouble in IE3, so it's best to use 'location.href' without the 'document.' bit. The replace is a nice idea, though. When using replace you write the new page over the old one in the history of the browser, while location.href merely adds a page to the history of the browser.
if (self != top) top.location = self.location
'location' is not enough for (I think) IE3 again, use 'location.href'
if (self.parent.frames.length != 0) self.parent.location=document.location
or
if (self.parent.frames.length != 0) self.parent.location="index.html";
All 'self.' can be deleted, but otherwise these ones are OK too, except that 'document.location' should read 'location.href'
if (parent.frame.length !=0) { window.open(self.location); window.stop(); }
With this one you open a pop-up with your site and stop loading the other site. I recommend against this one, too complicated.

login or register to post comments

The access keys for this page are: ALT (Control on a Mac) plus:

evolt.orgEvolt.org is an all-volunteer resource for web developers made up of a discussion list, a browser archive, and member-submitted articles. This article is the property of its author, please do not redistribute or use elsewhere without checking with the author.