How can I block Internet Explorer on my page? I need to avoid using my website with Internet Explorer 9 or less
How can I block Internet Explorer on my page? I need to avoid using my website with Internet Explorer 9 or less
You can use this javascript code with jQuery:
if ($.browser.msie && parseInt($.browser.version) <= 9){
$('body').html('<span> Este sitio no soporta IE version < 9.</span>');
}
Complementing the answer:
You can use Conditional Comments as well, which only work in Internet Explorer , but they are used to give additional instructions to your users or to load libraries (javascript) based on the version of IE:
<!--[if IE 6]>
De acuerdo al comentario condicional este es IE 6<br />
<![endif]-->
<!--[if IE 7]>
De acuerdo al comentario condicional este es IE 7<br />
<![endif]-->
<!--[if IE 8]>
De acuerdo al comentario condicional este es IE 8<br />
<![endif]-->
You can check additional information here .
What we do in some intranets / websites is to redirect to a page that displays the message "Not supported in Internet Explorer".
The script is very simple (I had to edit the method to validate IE see 9 or less, since it is something different, but now this method works with all of them).
<html>
<head>
</head>
<body>
<script language="javascript">
<!--
function getIEVersion() {
var match = navigator.userAgent.match(/(?:MSIE |Trident\/.*; rv:)(\d+)/);
return match ? parseInt(match[1]) : undefined;
}
if(getIEVersion() != undefined){
if (getIEVersion() <= 9) {
document.location = "http://www.puisormobile.com/no_ie.html"; //Es IE <= 9, REDIRECCIONA A PAGINA QUE SUGIERE USAR UNA MAYOR VERSIÓN!
}else{
document.location = "http://www.puisormobile.com/default.html"; // OK, Es IE > 9!
}
}else{
document.location = "http://www.puisormobile.com/default.html"; // OK, No es IE!
}
// -->
</script>
</body>
</html>
A more compact form and without using any library, not even JavaScript and that at least works from IE6. It has the advantage of working despite the fact that the user has JavaScript disabled.
Place this within the <head>
of your page:
<!--[if lt IE 10]>
<meta http-equiv="refresh" content="0;url=/ruta/a/actualiza_tu_navegador.html"></meta>
<![endif]-->
Explanation:
<!--[if lt IE 10]> .. <![endif]-->
If internet explorer version less than 10 (9 or less) <meta http-equiv="refresh"
go to content="0;url=pagina.html"
in 0 seconds, path: pagina.html
></meta>
Old versions of IE do not support the syntax <meta />
, you must use the syntax <meta></meta>
Finally, create a static page called actualiza_tu_navegador.html
, with the message you want and certainly you could include some links to download the browsers that you support.
If you want to block all versions of Internet Explorer change by <!--[if IE]>
Note: In other browsers that are not IE this is interpreted as a comment since the whole block starts with <!--
and ends with -->
. Therefore, it has no effect.
Make a redirection to a particular page that says something like: To use this website, we recommend using a higher version of IE or another updated browser.
To respond and avoid re-inventing the wheel, let's make use of Modernizr link
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "Other";
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "Unknown";
},
searchString: function (data) {
for (var i = 0; i < data.length; i++) {
var dataString = data[i].string;
this.versionSearchString = data[i].subString;
if (dataString.indexOf(data[i].subString) !== -1) {
return data[i].identity;
}
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index === -1) {
return;
}
var rv = dataString.indexOf("rv:");
if (this.versionSearchString === "Trident" && rv !== -1) {
return parseFloat(dataString.substring(rv + 3));
} else {
return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
}
},
dataBrowser: [
{string: navigator.userAgent, subString: "Edge", identity: "MS Edge"},
{string: navigator.userAgent, subString: "MSIE", identity: "Explorer"},
{string: navigator.userAgent, subString: "Trident", identity: "Explorer"},
{string: navigator.userAgent, subString: "Firefox", identity: "Firefox"},
{string: navigator.userAgent, subString: "Opera", identity: "Opera"},
{string: navigator.userAgent, subString: "OPR", identity: "Opera"},
{string: navigator.userAgent, subString: "Chrome", identity: "Chrome"},
{string: navigator.userAgent, subString: "Safari", identity: "Safari"}
]
};
BrowserDetect.init();
document.write("You are using <b>" + BrowserDetect.browser + "</b> with version <b>" + BrowserDetect.version + "</b>");
Finally, we review the following variables and, according to that, the aforementioned redirection
BrowserDetect.browser == 'Explorer';
BrowserDetect.version <= 9;
Credits of the answer: link