Frame busting code and AdSense
Posted in Javascript on November 19th, 2009 by Ilir Fekaj – 1 CommentIf you are tired of your site being framed by other sites or image search engines, you would certainly have thought of using some of Javascript code to kill unwanted frame. However, there is concern that this code may cause double page impression of your AdSense or other ads. To test this, I created a small experiment by adding Javascript alert near the end of my page so it runs after frame killer/redirect occurs. To my surprise, Chrome, Opera and Safari loaded two alert boxes, which effectively proved that all Javascript (including ads) is fired up twice. I solved this problem (hopefully) by stopping execution of all scripts after redirection. Here is my final code:
if (top.location != self.location) {
top.location.replace(self.location);
if(navigator.appName == "Microsoft Internet Explorer"){
window.document.execCommand('Stop');
}
else{
window.stop();
}
}
Please let me know what you think.