JavaScript Code

Have You Been Framed? Use JavaScript to Break the Frames!

A rather unscrupulous practice by some webmasters is falsifying content on their site by simply putting your content or site in a frame or iframe on their website. Well with this handy little code snippet you can make sure that no site frames yours.

This code will enable your page to break out of frames if it's put in a frameset. You'll want to put this in a JavaScript .js file, and include it in the head of every page of your website. Once the page is loaded, it will check to see if it's been put in a frame. If so, it will replace the 'top' href/address with your page's address, thus eliminating the frameset.

Assuming the file is named include.js, the code to include it is as follows, and it's placed in the <head> section of your page:


<script src="include.js" language="JavaScript" type="text/javascript"></script>

And the code is like this:


function breakFames()
{
  if (top.location != location) {
    top.location.href = document.location.href ;
  }
}

window.onload = breakFames;
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image