开发学院

您的位置:首页>教程>正文

教程正文

WebGL 兼容性检查

WebGL 兼容性检查

  尽管主流的浏览器兼容性问题越来越少,但一些设备或浏览器可能仍然不支持WebGL。以下方法允许您检查是否支持它,如果不支持,则向用户显示消息

  添加https://github.com/mrdoob/three.js/blob/master/examples/js/Detector.js 到你的js文件中并运行以测试你的设备是否支持

if (Detector.webgl) {
    // Initiate function or other initializations here
    animate();
} else {
    var warning = Detector.getWebGLErrorMessage();
    document.getElementById('container').appendChild(warning);
}