此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

WebGLRenderingContext.isContextLost()

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

WebGLRenderingContext.isContextLost() 方法返回一个Boolean 标记 WebGL 的上下文是否已经丢失。

语法

gl.isContextLost();

返回值

Boolean。如果上下文丢失则返回 true,否则返回 false。

样例

比如,当检查程序链接成功时,你也可以检查是否上下文已经丢失。

js
gl.linkProgram(program);

if (!gl.getProgramParameter(program, gl.LINK_STATUS) && !gl.isContextLost()) {
  var info = gl.getProgramInfoLog(program);
  console.log("Error linking program:\n" + info);
}

规范

规范
WebGL Specification
# 5.14.13

浏览器兼容性

参见