--- 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 ---
WEBGL_lose_context.restoreContext() 属于 WebGL API。 , 一般用来模拟 {{domxref("WebGLRenderingContext")}} 的上下文恢复。
gl.getExtension('WEBGL_lose_context').restoreContext();
INVALID_OPERATION 上下文尚未丢失你可以用这个方法模拟 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")}}
webglcontextlost, webglcontextrestored, webglcontextcreationerror