检查IE 10 [英] Check for IE 10
本文介绍了检查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
}
更新:
为了避免评论缩小,您可以使用以下内容:
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屋!
查看全文