检测不到HTML5 的最佳方式(Best way to detect that HTML5 is not supported)

编程入门 行业动态 更新时间:2024-10-28 06:32:00
检测不到HTML5 的最佳方式(Best way to detect that HTML5 is not supported)

处理浏览器不支持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()){ ...

更多推荐

本文发布于:2023-07-24 10:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1244909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   supported   detect

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!