Tuesday, November 16, 2010

Prevent site from getting loaded on iframe

What if somebody loads your obfuscated fancy javascript or AJAX methods to drive traffic to their site utilising your bandwidth? Here is a simple solution in javascript.

<script type="text/javascript">
    if (window.top !== window.self) {
        document.write = "";
        window.top.location = window.self.location;
        setTimeout(function () {
            document.body.innerHTML = '';
        }, 1);
        window.self.onload = function (evt) {
            document.body.innerHTML = '';

Paste that javascript snippet inside your head tag of your html.
Twitter(Dustin Diaz) uses that at the Twitter Profile Widget Page. :(
I found it the hard way (lol). Way to go Dustin!

Related Posts :

0 comments on "Prevent site from getting loaded on iframe"

Add your comment. Please don't spam!
Subscribe in a Reader

Post a Comment