Code/JavaScript

[JavaScript] Hide AdSense on Selected Pages

Hide Code 2009. 3. 5. 10:03
Hide AdSense on Selected Pages Sample Code


<html>
<body>

<script type="text/javascript">
// hide AdSense on selected pages
// add this code right before the </body> tag
var targetURLs = new Array();
targetURLs[0] = "procoder.tistory.com/1$"; // use Regular Expressions
targetURLs[1] = "procoder.tistory.com/2$";
targetURLs[2] = "procoder.tistory.com/3$";
targetURLs[3] = "procoder.tistory.com/1[0-9]{2}$";
for (var i in targetURLs)
{
   var myRegExp = new RegExp(targetURLs[i], "i"); // ignore case
   if (document.URL.match(myRegExp))
   {
      var myElements = document.getElementsByTagName("iframe");
      for (var j in myElements)
      {
         if (myElements[j].src.match(/googlesyndication.com/i))
         {
            myElements[j].style.display = "none";
         }
      }
   }
}
</script>
</body>
</html>