现代浏览器默认原生支持HTML5,无需安装或开启;确认特性需检测具体API(如typeof localStorage),而非笼统查“HTML5支持”;页面不工作多因新特性兼容性、file://协议限制、MIME错误、隐私模式或权限问题。现代浏览器默认已完整支持 HTML5,不需要额外“安
装”或“开启”HTML5 功能。
HTML5 不是插件,也不是开关选项——它是 W3C 标准,由浏览器内核原生实现。只要使用 Chrome 4+、Firefox 4+、Safari 5.1+、Edge 12+ 或 Opera 11.6+,audio、video、canvas、localStorage、fetch 等核心特性均已启用且无法关闭。
不要查“是否支持 HTML5”,而要查具体 API 是否可用。常见检测方式:
typeof 检查全局对象:typeof localStorage !== 'undefined'
in 检查属性:'geolocation' in navigator
!!document.createElement('canvas').getContext
fetch)问题通常不出在“HTML5 支持”上,而是以下原因:
Popover API、View Transitions),需查 caniuse.com 确认兼容性file:// 协议),导致 fetch、Service Worker、CORS 相关功能被禁用text/plain 而非 text/html)localStorage 或第三方 Cookie 相关 API避免直接假设 API 存在,始终做运行时检测:
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
.catch(err => console.warn('SW registration failed:', err));
} else {
console.log('Service Worker not supported');
}
对关键功能降级处理:
立即学习“前端免费学习笔记(深入)”;
时提供多个 格式(mp4 + webm)fetch 前检查:if (window.fetch),否则回退到 XMLHttpRequest
localStorage / indexedDB)需捕获 QuotaExceededError 或 SecurityError