[英]How can I detect if a browser supports the blink tag?
The HTML <blink>
tag, in browsers that support it (ie Mozilla Firefox and Opera), makes its content blink on and off, resembling the effect of a slow strobe light. HTML <blink>
标签,在支持它的浏览器(即Mozilla Firefox和Opera)中,使其内容闪烁,类似慢速闪光灯的效果。
I am writing a suite of polyfills for non-standard HTML, including the blink
tag. 我正在为非标准HTML编写一套polyfill,包括blink
标签。 The implementation of blinking behavior is pretty simple 闪烁行为的实现非常简单
(function blink(n) {
var blinks = document.getElementsByTagName("blink"),
visibility = n % 2 === 0 ? "visible" : "hidden";
for (var i = 0; i < blinks.length; i++) {
blinks[i].style.visibility = visibility;
}
setTimeout(function() {
blink(n + 1);
}, 500);
})(0);
(You can see this in action ) (你可以看到这个 )
But this does not detect if the browser already supports the blink
tag, and in browsers that already support it, there will be a double-blinking effect. 但是这并没有检测到浏览器是否已经支持blink
标签,并且在已经支持它的浏览器中,会出现双重闪烁效果。 I need some feature detection that determines if the browser supports blink, and if it doesn't then it falls back on my Javascript polyfill. 我需要一些功能检测来确定浏览器是否支持闪烁,如果没有,那么它会回到我的Javascript polyfill上。
I do not want to do browser detection, because that solution is not scalable, and since people can disable blink
behavior in their Firefox preferences, that solution is not effective. 我不想进行浏览器检测,因为该解决方案不可扩展,并且由于人们可以在Firefox首选项中禁用blink
行为,因此该解决方案无效。
Is there a way to detect support for the blink
element? 有没有办法检测blink
元素的支持?
I just did a little research on the matter and I think I may found an answer... 我刚刚对此事进行了一些研究, 我想我可能会找到答案......
I'm sure you're aware of CSS property support detection? 我确定你知道CSS属性支持检测? Well, there is a text-decoration: blink
CSS property. 好吧,有一个text-decoration: blink
CSS属性。 So if the browser supports <blink>
it must support the CSS property too! 因此,如果浏览器支持<blink>
它也必须支持CSS属性!
This is normal CSS property detection ie to detect textDecoration
is supported do this: 这是正常的CSS属性检测,即检测textDecoration
是否支持执行此操作:
if (document.createElement("detect").style.textDecoration === "") {
// textDecoration supported
}
Perhaps you could try something like this: 也许你可以尝试这样的事情:
if (document.createElement("detect").style.textDecoration === "blink") {
// textDecoration: blink supported ?
}
or along those lines... 或沿着这些方向......
I have 4 browsers & so tested this with 4 browsers. 我有4个浏览器,所以用4个浏览器进行测试。 Out of those 4 only FireFox supports the blink tag. 在这4个中,只有FireFox支持闪烁标记。 <blink>
is registered in the HTML document as a "Span" element in FF, but in the other 3 browsers it is registered as an unknown
element. <blink>
在HTML文档中作为FF中的“Span”元素注册,但在其他3个浏览器中,它被注册为unknown
元素。
<html>
<head>
<script type="text/javascript">
function investigate() {
var blinker = document.getElementsByTagName("blink")[0];
document.getElementById("monitor").innerHTML += blinker;
}
</script>
</head>
<body onload="investigate()">
<blink>Hello, blink!</blink>
<div id="monitor"> </div>
</body>
</html>
Internet Explorer [7,8,9] not supported Internet Explorer [7,8,9] 不受支持
Hello, blink! 你好,眨眼!
[object] [宾语]
Chrome [18] not supported Chrome [18] 不受支持
Hello, blink! 你好,眨眼!
[object HTMLUnknownElement] [对象HTMLUnknownElement]
Safari [5] not supported Safari [5] 不受支持
Hello, blink! 你好,眨眼!
[object HTMLElement] [对象HTMLElement]
FireFox [3.6] supported 支持 FireFox [3.6]
Hello, blink! 你好,眨眼!
[object HTMLSpanElement] [对象HTMLSpanElement]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.