html5中canvas学习笔记2-判断浏览器是否支持canvas
内容摘要
判断浏览器是否支持canvas,具体代码如下:
复制代码代码如下:
<!DOCTYPE html>
<head>
<meta charset=utf-8 />
<title>canvas</title>
<script type='text/javascript'
复制代码代码如下:
<!DOCTYPE html>
<head>
<meta charset=utf-8 />
<title>canvas</title>
<script type='text/javascript'
文章正文
判断浏览器是否支持canvas,具体代码如下:
<!DOCTYPE html>
<head>
<meta charset=utf-8 />
<title>canvas</title>
<script type='text/javascript'>
window.onload = function(){
/**判断浏览器是否支持canvas**/
try{
document.createElement('canvas').getContext('2d');
var addDiv = document.createElement('div');
addDiv.innerHTML='支持canvas';
document.body.appendChild(addDiv);
}catch(e){
var addDiv = document.createElement('div');
addDiv.innerHTML='浏览器不支持canvas';
document.body.appendChild(addDiv);
}
};
</script>
</head>
<body>
</body>
</html>
复制代码
代码如下:<!DOCTYPE html>
<head>
<meta charset=utf-8 />
<title>canvas</title>
<script type='text/javascript'>
window.onload = function(){
/**判断浏览器是否支持canvas**/
try{
document.createElement('canvas').getContext('2d');
var addDiv = document.createElement('div');
addDiv.innerHTML='支持canvas';
document.body.appendChild(addDiv);
}catch(e){
var addDiv = document.createElement('div');
addDiv.innerHTML='浏览器不支持canvas';
document.body.appendChild(addDiv);
}
};
</script>
</head>
<body>
</body>
</html>
代码注释