How to automatically break out of an iframe

Just recently I have released a free sms service located at sms.budflick.com — and a few days later found out that some webmasters are actually abusing my service by putting it on their websites and they take the credit. I was able to circumvent the problem, and made a free traffic out of their site 🙂

Here is a simple tip to prevent any page of your site from being used as an iframe content

Just put this nifty code on the <head> … </head> of your page (assuming it is PHP coded)

echo “<head>”;
… other code …
echo “<script language=”javascript” type=”text/javascript”>”;
echo “function antiTheft(){“;
echo “if (top.location!= self.location) {“;
echo “top.location = “http://www.blgr.info/”;”;
echo “}”;
echo “}”;
echo “</script>”;
echo “</head>”

and modify the <body> tag

echo “<body onload=”antiTheft()”>”;

Now, when your page is put in an iframe, this javascript code will check and automatically reload itself.

Leave a Reply

Your email address will not be published. Required fields are marked *