RSS Amplifier

(untitled) · May 25, 2015

How to detect WebGL support

0
Sign in to vote or save

This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.

Detect if browser supports WebGL. function webglDetect() { var canvas = document .createElement( 'canvas' ); var contextNames = [ 'webgl' , 'experimental-webgl' , 'moz-webgl' , 'webkit-3d' ]; var context; if (navigator.userAgent.indexOf( 'MSIE' ) > - 1 ) { try { context = WebGLHelper.CreateGLContext(canvas, 'canvas' ); } catch (e) {} } else { for ( var i = 0 ; i < contextNames.length; i ++ ) { try…

Detect if browser supports WebGL.

function webglDetect() {
 var canvas = document.createElement('canvas');
 var contextNames = ['webgl','experimental-webgl','moz-webgl','webkit-3d'];
 var context;

 if (navigator.userAgent.indexOf('MSIE') > -1) {
 try {
 context = WebGLHelper.CreateGLContext(canvas, 'canvas');
 } catch(e) {}
 } else {
 for (var i = 0; i < contextNames.length; i++) {
 try {
 context = canvas.getContext(contextNames[i]);
 if (context) {
 break;
 }
 } catch(e) {}
 }
 }

 return !!context;
}

Usage:

if (webglDetect()) {
 // WebGL is supported
}

On github at miguelmota/webgl-detect.

Read on miguelmota.com

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.