我正在创建一个脚本,用于检测浏览器是否与WebGL功能兼容html5。我可以很好地检测IE 9和10,但是在8及以下版本中,该按钮不起作用。我已经在此站点上进行了研究,需要针对IE 8及更低版本使用attachEvent vs 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>`