Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

javascript - 未捕获的ReferenceError:未定义WEBGL(Uncaught ReferenceError: WEBGL is not defined)

In my HTML, following code portion(在我的HTML中,以下代码部分)

if (WEBGL.isWebGLAvailable()==false) {
    document.body.appendChild(WEBGL.getWebGLErrorMessage());
}

generates following error on console:(在控制台上生成以下错误:)

Uncaught ReferenceError: WEBGL is not defined(未捕获的ReferenceError:未定义WEBGL)

I am already importing all necessary js, so the question is: how do you solve this?(我已经导入了所有必需的js,所以问题是:如何解决这个问题?)

  ask by Employee translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Seems like you're using three.js library.(似乎您正在使用three.js库。)

As the docs mention:(正如文档所述:)

Add https://github.com/mrdoob/three.js/blob/master/examples/jsm/WebGL.js to your javascript and run the following before attempting to render anything.(将https://github.com/mrdoob/three.js/blob/master/examples/jsm/WebGL.js添加到您的javascript中,并在尝试呈现任何内容之前运行以下命令。)

if ( WEBGL.isWebGLAvailable() ) {

    // Initiate function or other initializations here
    animate();

} else {

    var warning = WEBGL.getWebGLErrorMessage();
    document.getElementById( 'container' ).appendChild( warning );

}

So I don't think you actually loaded the required script.(因此,我认为您实际上并未加载所需的脚本。)

Source: https://threejs.org/docs/#manual/en/introduction/WebGL-compatibility-check(来源: https : //threejs.org/docs/#manual/en/introduction/WebGL-compatibility-check)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...