topical media & game development
basic-javascript-05-ch5-examp7.htm / htm
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function getBrowserName()
{
var lsBrowser = navigator.userAgent;
if (lsBrowser.indexOf("MSIE") >= 0)
{
lsBrowser = "MSIE";
}
else if (lsBrowser.indexOf("Netscape") >= 0)
{
lsBrowser = "Netscape";
}
else if (lsBrowser.indexOf("Firefox") >= 0)
{
lsBrowser = "Firefox";
}
else if (lsBrowser.indexOf("Safari") >= 0)
{
lsBrowser = "Safari";
}
else if (lsBrowser.indexOf("Opera") >= 0)
{
lsBrowser = "Opera";
}
else
{
lsBrowser = "UNKNOWN";
}
return lsBrowser;
}
function getBrowserVersion()
{
var findIndex;
var browserVersion = 0;
var browser = getBrowserName();
browserVersion = navigator.userAgent;
findIndex = browserVersion.indexOf(browser) + browser.length + 1;
browserVersion = parseFloat(browserVersion.substring(findIndex,findIndex + 3));
return browserVersion;
}
</script>
</head>
<body>
<script language="JavaScript" type="text/JavaScript">
var browserName = getBrowserName();
var browserVersion = getBrowserVersion();
if (browserName == "MSIE")
{
if (browserVersion < 5.5)
{
document.write("Your version of Internet Explorer is too old");
}
else
{
document.write("Your version of Internet Explorer is fully supported");
}
}
else if (browserName == 'Firefox')
{
document.write("Firefox is fully supported");
}
else if (browserName == 'Netscape')
{
if (browserVersion < 6)
{
document.write("Your version of Netscape is too old");
}
else
{
document.write("Your version of Netscape is fully supported");
}
}
else
{
document.write("<h2>Sorry this browser version is not supported</h2>");
}
</script>
<noscript>
<h2>This website requires a browser supporting scripting</h2>
</noscript>
</body>
</html>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.