I'm trying to add a textarea resizer plugin on my MVC project, but only for IE, since other browsers have a built-in one. In order to do that I have to check if the browser is IE.
I used the JS from this article: How to detect IE11?
So this is what I use:
function getInternetExplorerVersion() {
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer') {
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
else if (navigator.appName == 'Netscape') {
var ua = navigator.userAgent;
var re = new RegExp("Trident/.*rv:([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
return rv;
}
function checkVersion() {
var msg = "You're not using Internet Explorer.";
var rv = getInternetExplorerVersion();
if (rv > -1) {
msg = "You are using IE " + ver;
}
alert(msg);
}
I inserted it in my scripts folder and I access it through this line in Scripts section:
<script type="text/javascript" src="~/Scripts/checkIEVersion.js"></script>
Then I try to implement it on pageload:
<body onload="checkVersion()">
The problem is, nothing happens. I should get an alert, but I get no error, no nothing. When I use only the bottom of the two functions (in the Scripts section with "@(document).ready", it does load correctly.
Could you please assist me?
Thanks in advance!