Sunday, August 28, 2011

Javascript Exercise: Check if the browser support canvas

We can use the code document.createElement('canvas').getContext to check if the browser support HTML5 canvas feature. If the browser support HTML5 canvas feature, it return true, otherwise return false.

example:

Javascript Exercise: Check if the browser support canvas

<!DOCTYPE html>

<html>
<head>
<title>JavaScript Exercise</title>
<script type="text/javascript">

function CheckCanvas(){

if(document.createElement('canvas').getContext){
alert("OK. Your browser support canvas");
}else{
alert("Sorry! your brwser doesn't support canvas");
}

}


function htmlonload(){
CheckCanvas();
}
</script>
</head>
<body onload="htmlonload();">
JavaScript Exercise
</body>
</html>




No comments:

Post a Comment