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.href=self.document.href; }

Frameset prevention script #2
<script type=”text/javascript”>
function breakOut() {
if (self != top)“my URL”,”_top”,””);

Frameset prevention script #3
if (window!=top){top.location.href=location.href;}

[tags]prevent framed, prevent frameset, frameset prevention, no frame, frameset hijack[/tags]

Share this with your friends:-

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

  1. Jon says:

    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.

  2. SoGua says:

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

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

Leave a Reply