Javascript: Prevent page from frameset hijack

If you would like to prevent your site being frame by other website, you can use the code below to protect your site being frame.
Basically, the javascript check if your site is being open by frameset. It check if the opening window is top or else it will refresh the page to your site URL.
Many unethical site nowdays like to “wrap” other people website using FRAME at their website to show other website as it’s own website. This will mislead the visitor that the content is owned by them.
Frameset prevention script #1
<script type=”text/javascript”>
if (top.frames.length!=0) {
if (window.location.href.replace)
top.location.replace(self.location.href);
else
top.location.href=self.document.href; }
</script>
Frameset prevention script #2
<script type=”text/javascript”>
function breakOut() {
if (self != top)
window.open(“my URL”,”_top”,”");
}
</script>
Frameset prevention script #3
<script>
if (window!=top){top.location.href=location.href;}
</script>
Tags: frameset hijack, frameset prevention, javascript, javascript tutorial, no frame, prevent framed, prevent frameset
Posted at April 17th, 2007 by chua
If you think this article helps you to solve your problem and clear your headache, feel free to buy me a drink :)



January 14th, 2008 at 7:42 am
So do i use just one of those methods ? or all 3 ?.. and where do i apply the code ? in the EHad or directly after the BODY tag ??
January 16th, 2008 at 3:06 pm
choose any one from the three methods.
put it between the tag
November 4th, 2008 at 10:48 pm
I have a site with 2 frames, one of the hijacked sites use the above codes. How can I prevent them to do that? I just want the site showing in one of my frames.