2

Some websites seem to have replaced their hyperlinks to my website with (small-sized) iframes. These iframes cause my bandwidth usage to increase, and ad clicks to decrease (ads are now displayed far below the fold and scrollbars are removed). I'm not talking about just a few clicks, but I'm talking about a loss of at least $400 USD a day.

I want to discourage iframing of my website by making the parent window redirect to my website. I've tried the simple "window.top.location.href" trick, but that hasn't solved the issue. The websites are using a script to display an "Are you sure you want to leave...?"-confirm popup when leaving the page (obviously causing my redirect to stop).

Is there any way I can still force a redirect, or maybe another solution?

Jason
  • 439
  • 1
  • 6
  • 21
  • 1
    There is a header that would block your site being displayed in an iframe in modern browsers, is that an option as well? – Pekka Dec 17 '12 at 13:13
  • See this page too: http://stackoverflow.com/questions/5881139/how-to-block-iframe-call – CoursesWeb Dec 17 '12 at 13:24

1 Answers1

2

You can look as it's done in facebook:

<script type="text/javascript">
        /* <![CDATA[ */if (top != self) { 
           try { if (parent != top) { throw 1; } 
           var disallowed = ["apps.facebook.com","\/pages\/","apps.beta.facebook.com"];
            href = top.location.href.toLowerCase(); 
              for (var i = 0; i < disallowed.length; i++) {
                  if (href.indexOf(disallowed[i]) >= 0) { throw 1; } 
              } 
          } catch (e) {
             setTimeout(
                   function() {var fb_cj_img = new Image(); 
                      fb_cj_img.src = "http:\/\/error.facebook.com\/common\/scribe_endpoint.php?c=si_clickjacking&m=on\u002509&t=8183";}, 5000); 
        window.document.write("\u003cstyle>body * { display:none !important; }\u003c\/style>\u003ca href=\"#\" onclick=\"top.location.href=window.location.href\" style=\"display: block !important; padding: 10px\">\u003ci class=\"img sp_8dfqpl sx_d67a9a\" style=\"display:block !important\">\u003c\/i>Go to Facebook.com\u003c\/a>");

        /* XRCm4Hhw */ }}/* ]]> *

</script>
antyrat
  • 27,479
  • 9
  • 75
  • 76