--- title: WEBGL_lose_context.restoreContext() slug: Web/API/WEBGL_lose_context/restoreContext tags: - API - Method - Reference - WebGL - WebGL extension translation_of: Web/API/WEBGL_lose_context/restoreContext ---
{{APIRef("WebGL")}}

WEBGL_lose_context.restoreContext() 属于 WebGL API。 , 一般用来模拟 {{domxref("WebGLRenderingContext")}} 的上下文恢复。

语法

gl.getExtension('WEBGL_lose_context').restoreContext();

抛出错误

示例

你可以用这个方法模拟  webglcontextrestored 事件:

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

canvas.addEventListener('webglcontextrestored', function(e) {
  console.log(e);
}, false);

gl.getExtension('WEBGL_lose_context').restoreContext();

规范

Specification Status Comment
{{SpecName('WEBGL_lose_context', "", "WEBGL_lose_context.loseContext")}} {{Spec2('WEBGL_lose_context')}} Initial definition.

浏览器兼容性

{{Compat("api.WEBGL_lose_context.restoreContext")}}

相关链接