How to check the user is using Internet Explorer in JavaScript?
There may arise cases when we need to check the browser being used. Some features of your website may not be supported in older browsers like Internet Explorer(IE). There are different ways to check the version of Internet Explorer being used.
Syntax-1: For Internet Explorer 10 or older
var ua = window.navigator.userAgent;
var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}
Syntax-2: For Internet Explorer 11
var ua = window.navigator.userAgent;
var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}
Syntax-3: For Internet Explorer 12+ (Edge)
var ua = window.navigator.userAgent;
var edge = ua.indexOf('Edge/');
if (edge > 0) {
// Edge (IE 12+) => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);
}
Example:
<!DOCTYPE html> <html> <head> <title> Detects user uses Internet Explorer </title> </head> <body> <center> <h1 style="color:green">GeeksforGeeks</h1> <script> //detects if user uses Internet Explorer //returns version of IE or false, if browser is not IE //Function to detect IE or not function IEdetection() { var ua = window.navigator.userAgent; var msie = ua.indexOf('MSIE '); if (msie > 0) { // IE 10 or older, return version number return ('IE ' + parseInt(ua.substring( msie + 5, ua.indexOf('.', msie)), 10)); } var trident = ua.indexOf('Trident/'); if (trident > 0) { // IE 11, return version number var rv = ua.indexOf('rv:'); return ('IE ' + parseInt(ua.substring( rv + 3, ua.indexOf('.', rv)), 10)); } var edge = ua.indexOf('Edge/'); if (edge > 0) { //Edge (IE 12+), return version number return ('IE ' + parseInt(ua.substring( edge + 5, ua.indexOf('.', edge)), 10)); } // User uses other browser return ('Not IE'); } var result = IEdetection(); document.write(result); </script> </center> </body> </html> |
Output (Opening with Firefox):
Not IE
Output (Opening with IE 11):
IE 11
Output (Opening with Edge):
IE 18
Recommended Posts:
- JavaScript Course | Interaction With User
- Detect the Operating System of User using JavaScript
- How to display hidden element when a user starts typing using JavaScript ?
- How to detect the user browser ( Safari, Chrome, IE, Firefox and Opera ) using JavaScript ?
- Substring check in JavaScript
- JavaScript | Check if a variable is a string
- JavaScript | Check the existence of variable
- How to check if string contains only digits in JavaScript ?
- How to Check/Uncheck the checkbox using JavaScript ?
- How to check a key exists in JavaScript object?
- How to check if an element has any children in JavaScript ?
- How to check a date is valid or not using JavaScript ?
- How to check object is an array in JavaScript?
- Check if an array is empty or not in JavaScript
- How to check a function is defined in JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


