Making addEventListener cross browser compatible with IE8 and below

90 views Asked by At

I am creating a script for detecting whether or not a browser is html5 compatible with the WebGL feature. I have it working fine for detecting IE 9 and 10, but in 8 and below, the button doesn't work. I've researched on this site that I need to use attachEvent vs addEventListener for IE 8 and below, but adding in the if/else statements I saw on this site makes my button not work in any browser. I know I probably have the syntax wrong. Any help would be much appreciated. My code is included. -Shawn

<!DOCTYPE html>
<html>
<body>


<button id= "button1">PRS PST</button>
<script>

// Run everything inside window load event handler, to make sure
// DOM is fully loaded and styled before trying to manipulate it.

window.addEventListener("load", function() { 
  var paragraph = document.getElementById("test"),
    button = document.getElementById("button1");
  // Adding click event handler to button.
  button.addEventListener("click", detectWebGLContext, false);
  function detectWebGLContext () {
    // Create canvas element. The canvas is not added to the
    // document itself, so it is never displayed in the
    // browser window.
    var canvas = document.createElement("canvas");
    // Get WebGLRenderingContext from canvas element.
    var gl = canvas.getContext("webgl")
      || canvas.getContext("experimental-webgl");
    // Report the result.
    if (gl && gl instanceof WebGLRenderingContext) {
      window.open("http://modsim01.icfconsulting.com/PUBLIC/PRS/prs-pst-raw-iwlpf923/index.html",'_blank', 'location=yes,resizable=yes,height=570,width=520,scrollbars=yes,status=yes');
    } else {
      window.open("http://modsim01.icfconsulting.com/PUBLIC/PRS/PDFLInks.html",'_blank', 'location=yes,resizable=yes,height=570,width=520,scrollbars=yes,status=yes');
    }
  }
}, false);


</script>


</body>
</html>`
0

There are 0 answers