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");
}
My webpage is a JSF facelet (XHTML).
Press the Alt key (next to the Spacebar) on the keyboard to open a menu bar. Click Help and select About Internet Explorer. The IE version is displayed in the pop-up window.
Internet Explorer 11 (Version 20H2)
To detect whether the current browser is Internet Explorer, you can make use of the navigator. userAgent property. The userAgent property returns the value of the user-agent header sent by the browser to the server. It contains information about the name, version, and platform of the browser.
IETester IETester is a software that is free to download. It allows you to run your web pages across multiple versions of Internet Explorer, even as low as IE5. 5 It also allows the user to check how the website performs on different browser versions in Windows 10, 7, Vista and XP.
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
}
Reference: How can I detect IE10 from JS when browser mode is IE9?
UPDATE:
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;
}());
And access the properties like IE.isTheBrowser
and IE.actualVersion
(which is translated from internal values of JScript versions).
In general, the practice of User Agent sniffing and conditional compilation/comments are best avoided. It is far better to use feature detection, graceful degradation , and progressive enhancement instead. However, for the few edge cases where it is more convenient for the developer to detect the browser version, you can use the following code snippets:
This if
statement will only execute on IE 10
// IF THE BROWSER IS INTERNET EXPLORER 10
if (navigator.appVersion.indexOf("MSIE 10") !== -1)
{
window.alert('This is IE 10');
}
This if
statement will only execute on IE 11
// IF THE BROWSER IS INTERNET EXPLORER 11
var UAString = navigator.userAgent;
if (UAString.indexOf("Trident") !== -1 && UAString.indexOf("rv:11") !== -1)
{
window.alert('This is IE 11');
}
http://jsfiddle.net/Qz97n/
Here's a method for getting the current IE or the IE Version:
function IE(v) {
return RegExp('msie' + (!isNaN(v)?('\\s'+v):''), 'i').test(navigator.userAgent);
}
Here's how you can use it:
if(IE()) alert('Internet Explorer!');
if(IE(10)) alert('Internet Explorer 10!');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With