7 July 2021
To block Internet Explorer from accessing your website using JavaScript, you can use user agent detection to identify Internet Explorer and then display a message or redirect users to another page. Here's a code snippet to achieve this:
if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') !== -1) {
// Redirect to another page or display a message
window.location.href = 'https://www.example.com/unsupported-browser';
}
This code checks if the user agent string contains 'MSIE' (for older versions of Internet Explorer) or 'Trident/' (for Internet Explorer 11) and then redirects users to an 'unsupported-browser' page. Replace 'https://www.example.com/unsupported-browser' with the URL of the page you want to redirect users to or display a message.
Keep in mind that this method relies on user agent strings, which can be easily spoofed. It's not a foolproof solution, but it should work for most users.
Another approach to prevent users from accessing your website using Internet Explorer is to use the <!--[if IE]> conditional comments, which are only recognized by Internet Explorer:
if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') !== -1) {
// Redirect to another page or display a message
window.location.href = 'https://www.example.com/unsupported-browser';
}
Various versions have evolved over the years, sometimes by accident.