1. Home
  2. Computing & Technology
  3. JavaScript

Frame Breakout

3. Force Page Reload

clr gif
More of this Feature

Frame Breakout Selective Breakout

Someone using my frame breakout code was surprised to find that someone had managed to set up frames on their site that included pages with the frame breakout code on them but where the pages didn't break out of frames.

The site that was displaying these pages in frames was being particularly clever in that they were using server side processing to embed the entire page inside of a page on their own site. This page on their site was then displayed in frames and the code they had added around the page made sure that when the page reloaded that it automatically reloaded within their frameset. The reason for the frame breakout not working is that they had managed to get both top.location and self.location refering to pages on their site and so the page was always reloaded inside of the page from the other site.

Once I realised how the frame breakout code was being bypassed I then came up with a solution that has the frame breakout code force the page to be reloaded from your site rather than from the overridden self.location. The code to do it looks like this:

<script type="text/javascript">
var thisPage = "http://javascript.about.com"
+ self.location.pathname;
if (top.location != thisPage)
top.location = thisPage;
</script>

Simply substitute the domain name of your site where I put javascript.about.com.

The result of using this code in place of the standard frame breakout code is that any sites that have forced self.location to be overridden with a location on their site through having embedded your page into theirs will be ineffective as only the pathname portion of the entry is used and the page will always be reloaded from your site.

Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.