Java Reference
In-Depth Information
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;
}
function checkBrowser()
{
if (getBrowserName() != “MSIE”)
{
window.location.replace(“notieonly.htm”);
}
}
</script>
</head>
<body onload=”checkBrowser()”>
<h2>Welcome to the Internet Explorer only page</h2>
</body>
</html>
Starting with the
ieonly.htm
page, fi rst you add an
onload
event handler, connected to the
checkBrowser()
function, so that the function is called when the page loads.
<body onload=”checkBrowser()”>
Then, in
checkBrowser()
, you use your
getBrowserName()
function to tell you which browser the
user has. If it's not IE, you replace the page loaded with the
notieonly.htm
page. Note that you use
replace()
rather than
href
, because you don't want the user to be able to click the browser's Back button.
This way it's less easy to spot that a new page is being loaded.
function checkBrowser()
{
if (getBrowserName() != “MSIE”)