【问题标题】:How to catch "You need a browser which supports WebGL to run this content." error?如何捕捉“您需要一个支持 WebGL 的浏览器来运行此内容。”错误?
【发布时间】:2017-04-20 21:30:18
【问题描述】:

我的 WebGL 浏览器游戏不适用于在 Chrome 中未选中“在可用时使用硬件加速”设置的用户,他们收到一条消息,提示“您需要支持 WebGL 的浏览器才能运行此内容,请尝试使用火狐”。我想捕捉这个错误,并显示一条自定义消息/将它们发送到我的指南页面,该页面向他们展示如何在 Chrome 中启用硬件加速,这样它们就不会被关闭并一起离开。我怎么能做到这一点?

【问题讨论】:

标签: javascript google-chrome unity3d unity-webgl


【解决方案1】:

以下代码对你有用:

var hasWebGL = (function() {
  if (!window.WebGLRenderingContext) {
    return 0;
  }

  var canvas = document.createElement('canvas');
  var gl = canvas.getContext("webgl");

  if (!gl) {
    gl = canvas.getContext("experimental-webgl");
    if (!gl) return 0;
  }

  return 1;
})();

if (!hasWebGL) alert('Custom message!');

但你可能想检查一下the full script,我在那里找到了检查 webgl 兼容性的。

希望对你有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 2016-10-07
    • 2012-12-26
    相关资源
    最近更新 更多