Javascript: Prevent page from frameset hijack

Advertisement ∇

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>

Technorati Tags: , , , ,

Share and Enjoy:
  • Reddit
  • BlinkList
  • del.icio.us
  • Digg
  • Fark
  • IndianPad
  • StumbleUpon
  • YahooMyWeb
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 :)

Related Post

2 Responses to “Javascript: Prevent page from frameset hijack”

  1. gaz Says:

    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 ??

  2. SoGua Says:

    choose any one from the three methods.
    put it between the tag

Leave a Reply