Uncategorized

Detect Internet Explorer and display a warning message to change the browser

0
314
2020 / 02 / 28

As you all know that the Microsoft has ended the support for the Internet Explorer browser. The modern web technologies are also not supporting it.

The Problem

You may see sites which says that the website is not supported with Internet Explorer e.g. one of the most popular website in the JavaScript developers is jsfiddle.net and when you open it in Internet Explorer you will see the following warning:

This image was taken in February 2020

You might want to create a website in the latest technology stack which works perfectly in all browsers and suddenly when you open it on Internet Explorer you shout “What a holy shit! The site is not working at all”. The problem is with the Internet Explorer which Microsoft has stopped its support, even the Microsoft Security Chief says that the Internet Explorer is not a browser. Lol!

How you may detect which browser it is?

There are many different ways for detecting the browser. Nowadays, you can also detect the platform device and the operating system installed on it using both PHP and JavaScript.

In this article, we will detect the browser using simple JavaScript code which will tell whether the user is using Internet Browser or not.

<script type='text/javascript'>
	function isItIE() {
	  user_agent = navigator.userAgent;
	  var is_it_ie = user_agent.indexOf("MSIE ") > -1 || user_agent.indexOf("Trident/") > -1;
	  return is_it_ie; 
	}
	if (isItIE()){
	    console.log('It is Internet Explorer');
	}else{
	    console.log('It is not Internet Explorer');
	}
</script>

This is a standalone code and does not require jQuery or any other JavaScript library to involve.

Using this code you can detect the browser and can display an alert message to change the browser.

Hi, I am a full-stack web developer with 5+ years of experience in working with different web technologies. Do you want to ask something? just send me a message through the contact form. Please visit my portfolio at hamzamehmood.com. Thanks