...

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



runeveryday
09-29-2012, 03: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,

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


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

WolfShade
10-05-2012, 10:46 PM
+1 to jalarie

Old Pedant
10-06-2012, 01: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum