title: Javascript to prevent clickjacking
body: <p>I have this Javascript snippet in my application to prevent clickjacking:</p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
       var style = document.createElement('style');
       style.type = "text/css";
       style.id = "antiClickjack";
       style.innerHTML = "body{display:none !important;}";
       document.head.appendChild(style);
  
       if (self === top) {
           var antiClickjack = document.getElementById("antiClickjack");
           antiClickjack.parentNode.removeChild(antiClickjack);
       } else {
           top.location = self.location;
       }
  &lt;/script&gt;
  </code></pre>
  
  <p>Basically, it creates a style element (CSS on the fly) to hide the body of the current page by default. Then, <em>if it doesn't</em> detect clickjacking, it deletes it. So, doing it this way, everyone who doesn't have Javascript can see the page too (although they won't be protected from clickjacking).</p>
  
  <p>It works for every browser except for Internet Explorer, which throws a <strong>Unknown runtime error</strong> exception. Does someone have a suggestion on how to fix this?</p>
  
  <p>Thanks :-)</p>