web-component - 自定义元素 v1 功能检测:针对不支持的浏览器的消息
问题描述
我正在为支持的浏览器开发自定义元素
寻找一种不太复杂的自定义元素特征检测方法,
我想出了:
<STYLE onload="if('customElements' in window)this.innerHTML=''">
body::before {
font-size: 2em;
color: red;
content: 'This Browser does NOT support modern W3C WebComponents (Custom Elements v1)';
}
</STYLE>
我不是 100% 确定;这种方法可能会闪烁文本(非常非常简短)
问题:是否有更优雅的解决方案来进行自定义元素特征检测?
组件
解决方案
通过使用类或其他东西来保护 CSS,然后如果条件正确,让 JS 代码添加所需的类:
<script>
if(!('customElements' in window)) {
document.body.classList.add('no-web-components');
}
</script>
<style>
body.no-web-components::before {
font-size: 2em;
color: red;
content: 'This Browser does NOT support modern W3C WebComponents (Custom Elements v1)';
}
</style>
此外,如果您打算这样做,您可能还想提供一个指向页面的链接,向他们展示在哪里下载更好的浏览器。
推荐阅读
- javascript - 对 React Hooks 的 useFetch 函数进行单一条件调用的正确方法?
- c# - 测试实体框架核心迁移
- xml - RCP 应用程序中的 Eclipse XML 编辑器不工作
- javascript - React Formik:如何使用自定义函数 onChange 和 onConfirmChange 进行请求输入
- gnuplot - Octave 错误:Gnuplot 版本太旧(使用最新的 5.2)
- swift - 核心数据多线程问题
- reactjs - 反应只在加载时调用方法一次
- python - 返回多个返回值的函数的 Python 类型提示
- c# - 如何在 C# 中从键盘输入日期时间变量
- ios - 苹果验证网址