处理浏览器不支持HTML5 <canvas>标记的情况的标准方法是嵌入一些备用内容,如:
<canvas>Your browser doesn't support "canvas".</canvas>但是页面的其余部分保持不变,这可能是不恰当或误导的。 我想要一些检测画布不支持的方式,以便相应地显示我的页面的其余部分。 你会推荐什么
The standard way to deal with situations where the browser does not support the HTML5 <canvas> tag is to embed some fallback content like:
<canvas>Your browser doesn't support "canvas".</canvas>But the rest of the page remains the same, which may be inappropriate or misleading. I'd like some way of detecting canvas non-support so that I can present the rest of my page accordingly. What would you recommend?
最满意答案
这是Modernizr中使用的技术,基本上每个其他绘画工作的图书馆都是:
function isCanvasSupported(){ var elem = document.createElement('canvas'); return !!(elem.getContext && elem.getContext('2d')); }由于您的问题是在不支持的情况下进行检测,因此我建议使用它:
if (!isCanvasSupported()){ ...This is the technique used in Modernizr and basically every other library that does canvas work:
function isCanvasSupported(){ var elem = document.createElement('canvas'); return !!(elem.getContext && elem.getContext('2d')); }Since your question was for detection when it's not supported, I recommend using it like so:
if (!isCanvasSupported()){ ...更多推荐
发布评论