<HTML> <HEAD> <TITLE>MSDN Online Samples: Version Control</TITLE> <META NAME="FILENAME" CONTENT="version_JS.HTM"> <STYLE> A:link { color:#003399; text-decoration:none; } A:visited { color:#6699CC; text-decoration:none; } A:hover { text-decoration:underline; } </STYLE> </HEAD> <BODY TOPMARGIN=20 LEFTMARGIN=40 bgcolor="#FFFFFF" LINK="#000066" VLINK="#666666" TEXT="#000000"> <!--TOOLBAR_START--> <!--TOOLBAR_EXEMPT--> <!--TOOLBAR_END--> <H2> </H2> <FONT FACE="verdana,arial,helvetica" SIZE=1> </FONT> <P> <P> <FONT FACE="verdana,arial,helvetica" SIZE=2> <FORM name=Form1> <INPUT name=iebutton onclick="iebutton_click(this);" type=Button value="Are you running IE?"> </FORM> <SCRIPT LANGUAGE="JavaScript"> function iebutton_click(b) { if (window.RunningIE5 == true) { b.value = "IE 5 is running"; } else { if (window.RunningIE4 == true) { b.value = "IE 4 is running"; } else { if (window.IEVersion <= 0) { b.value = "Not running IE"; } else { b.value = "Running IE 3"; } } } } </SCRIPT> <SCRIPT LANGUAGE="JavaScript"> function msieversion() // return Microsoft Internet Explorer (major) version number, or 0 for others // This function works by finding the "MSIE " string and extracting the version number // following the space, up to the decimal point for the minor version which is ignored. { var ua = window.navigator.userAgent var msie = ua.indexOf ( "MSIE " ) if ( msie > 0 ) // is Microsoft Internet Explorer; return version number return parseInt ( ua.substring ( msie+5, ua.indexOf ( ".", msie ) ) ) else return 0 // is other browser } window.IEVersion = msieversion(); window.RunningIE4 = (window.IEVersion == 4); window.RunningIE5 = (window.IEVersion == 5); </SCRIPT> <HR> <TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0> <TR> <TD ALIGN=LEFT VALIGN=TOP COLSPAN=2><FONT FACE="Verdana, Arial, Helvetica" SIZE="2"><B>Description</B></FONT></TD> </TR> <TR> <TD ALIGN=LEFT VALIGN=TOP COLSPAN=2><FONT FACE="Verdana, Arial, Helvetica" SIZE="2">The script on this page performs tests to determine whether the browser is running Internet Explorer. It creates a Boolean "Expando" property on the window object "RunningIE4" and "RunningIE5" that allows for easy checking in any scripts included later in the page.</FONT></TD> </TR> <TR> <TD ALIGN=LEFT VALIGN=TOP COLSPAN=2><FONT FACE="Verdana, Arial, Helvetica" SIZE="2"><P><BR><B>Browser compatibility</B></FONT></TD> </TR> <TR> <TD ALIGN=LEFT VALIGN=TOP COLSPAN=2><FONT FACE="Verdana, Arial, Helvetica" SIZE="2">This function will work on any browser that supports JavaScript.</FONT></TD> </TR> <TR> <TD ALIGN=LEFT VALIGN=TOP COLSPAN=2><FONT FACE="Verdana, Arial, Helvetica" SIZE="2"><P><BR><B>Usage</B></FONT></TD> </TR> <TR> <TD ALIGN=LEFT VALIGN=TOP COLSPAN=2><FONT FACE="Verdana, Arial, Helvetica" SIZE="2">Use version control functionality in your code if you want to write conditional code based on the user's browser.</FONT></TD> </TR> <P><BR> </TABLE> <BR> </FONT> <P> <P> <P> </BODY> </HTML>