View Full Version : some code of making a condition to the IE browser?

09-29-2012, 02:56 PM
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,

10-05-2012, 09:29 PM
How about something much simpler:

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

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.