CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   some code of making a condition to the IE browser? (http://www.codingforums.com/showthread.php?t=274700)

runeveryday 09-29-2012 02:56 PM

some code of making a condition to the IE browser?
 
Code:

if (navigator.appName == "Microsoft Internet Explorer") {
begin = navigator.userAgent.indexOf("MSIE ") +
"MSIE ".length;
if(navigator.userAgent.indexOf(";", begin) > 0) {
end = navigator.userAgent.indexOf(";", begin);
} else {
end = navigator.userAgent.indexOf(")", begin)
+ 2;
}
document.getElementById("targetDiv").innerHTML =
"You are using Internet Explorer " +
navigator.userAgent.substring(begin, end);
}
}

i don't know why there added an else part? what's the meaning and effect of it? thank you,

jalarie 10-05-2012 09:29 PM

How about something much simpler:
Code:

<!--[if IE]>
  <p>You are using Internet Explorer.  How sad.</p>
<![endif]-->


WolfShade 10-05-2012 09:46 PM

+1 to jalarie

Old Pedant 10-06-2012 12:43 AM

LOL! Too true!

But to answer his question:

APPARENTLY (and this is only from examining the code, not from personal knowledge) some version of MSIE have a userAgent string that includes "MSIE xx;" and other versions have "MSIE (something)xx". So all that code is doing is finding where the beginning and end of "xx" is.

It could have all been done much simpler using a regular expression, if anybody cares.


All times are GMT +1. The time now is 02:46 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.