0

I have been looking for a solution to prevent loading of my site from anywhere other than my site. Meaning can I prevent or at least put measure in place to deter loading of my site in frames and iframes from other sites. I have seen some useful answers here for similar questions but I was wondering about going at it from another direction. Is it possible to onload check browser url if anything other than www.mysite.com/ then force reload of www.mysite.com/ . Can this be done in javascript as my familiarity of other languages is limited. Here is an example of the code I was trying but it isn't working the way I want. It is reloading the iframe only and allowing the the leaching site to remain. I need to force a full page reload to my site. What am I missing?

    <script type="text/javascript" language="JavaScript">
    <!-- 
    if( -1 == location.href.
       toLowerCase().
       indexOf('mysite.com') )
    {
      location.href = 'http://mysite.com';
    }
    // -->
    </script> 
David Johnson
  • 21
  • 1
  • 3

1 Answers1

3

List of FrameBusters available from here and pasted below for future reference.


1.

if (window.top!=window.self){window.top.location="thepage_the_buster_is_on.php";}

2.

if (top.location!= location) {top.location.replace(self.location.href);}

3.

if( window!= window.top ) {top.location.href = location.href;}

4.

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

5.

if (parent.frames.length > 0) top.location.replace(document.location);

JosephGarrone
  • 4,081
  • 3
  • 38
  • 61
  • 1
    I don't think this works. You cannot modify the top location from a different domain. – Christophe Oct 21 '13 at 22:28
  • so it is not possible to load a new page from within a frame/iframe. I am sure I have seen codes before that allow an iframe to load a new page upon click. I just want it to happen upon load if url = anything other than mine? – David Johnson Oct 21 '13 at 22:49
  • Kazzzaaa Thanks Asryael. I tried your code and unfortunately it crashed my site. Not sure why but any way I grab just the top line from you and that seems to do exactly what I wanted. The site that was leeching me is now reloading my site every time it trys to put me in an iframe. Here what I used. – David Johnson Oct 21 '13 at 23:09
  • yes thank you Asryael I used just part of your script but it did the trick. Many thanks – David Johnson Oct 22 '13 at 13:03
  • @DavidJohnson please mark as answer on the left if this helped you. – JosephGarrone Oct 22 '13 at 22:38
  • the replace() function takes two arguements i think in Js.. – Ryan Stone Nov 25 '20 at 21:14
  • Thank you for these solutions! Just want to add a comment since this is almost 9 years old now, and things change: Solution 1 did not seem to work - I got an alert in Chrome that the redirect was blocked. Solutions 2, 3, and 4 all worked. Solution 5 gave an endless reload loop. – iaacp Aug 02 '22 at 18:42