检查 IE 10 [英] Check for IE 10
问题描述
如果用户使用的是 IE 10,如何在页面加载时显示消息框?
How can I make a message box appear on page load if the user is using IE 10?
function ieMessage() {
alert("Hello you are using I.E.10");
}
我的网页是一个 JSF facelet (XHTML).
My webpage is a JSF facelet (XHTML).
推荐答案
在没有条件注释和用户代理嗅探的情况下,检测这种情况的真正方法是使用条件编译:
The real way to detect this, without conditional comments and without User Agent sniffing is with conditional compilation:
<script type="text/javascript">
var isIE10 = false;
/*@cc_on
if (/^10/.test(@_jscript_version)) {
isIE10 = true;
}
@*/
console.log(isIE10);
</script>
运行此代码后,您可以随时使用以下内容:
After running this code, you can use following anytime after:
if (isIE10) {
// Using Internet Explorer 10
}
参考:我该怎么做当浏览器模式为IE9时,从JS检测IE10?
更新:
为了避免评论的缩小,您可以使用以下内容:
To avoid minification of comments, you can use something like:
var IE = (function () {
"use strict";
var ret, isTheBrowser,
actualVersion,
jscriptMap, jscriptVersion;
isTheBrowser = false;
jscriptMap = {
"5.5": "5.5",
"5.6": "6",
"5.7": "7",
"5.8": "8",
"9": "9",
"10": "10"
};
jscriptVersion = new Function("/*@cc_on return @_jscript_version; @*/")();
if (jscriptVersion !== undefined) {
isTheBrowser = true;
actualVersion = jscriptMap[jscriptVersion];
}
ret = {
isTheBrowser: isTheBrowser,
actualVersion: actualVersion
};
return ret;
}());
并访问诸如 IE.isTheBrowser
和 IE.actualVersion
(从 JScript 版本的内部值转换而来)等属性.
And access the properties like IE.isTheBrowser
and IE.actualVersion
(which is translated from internal values of JScript versions).
这篇关于检查 IE 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!