0

我正在创建一个脚本来检测浏览器是否与 WebGL 功能兼容 html5。我可以很好地检测 IE 9 和 10,但在 8 及以下版本中,该按钮不起作用。我在这个网站上研究过,我需要在 IE 8 及以下版本中使用 attachEvent 和 addEventListener,但是添加我在这个网站上看到的 if/else 语句会使我的按钮在任何浏览器中都不起作用。我知道我可能语法错误。任何帮助将非常感激。我的代码包括在内。-肖恩

<!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>`
4

0 回答 0