Java Reference
In-Depth Information
Exercise 2 Question
Create two pages, one called ieonly.htm and the other called notieonly.htm. Each page should have
a heading telling you what page is loaded. For example:
<H2>Welcome to the Internet Explorer only page</H2>
Using the functions for checking browser type, connect to the window object's onload event handler and
detect what browser the user has. Then, if it's the wrong page for that browser, redirect to the other page.
Exercise 2 Solution
The notieonly.htm page is as follows:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Chapter 6: Example Question 2</title>
<script type=”text/javaScript”>
function getBrowserName()
{
var lsBrowser = navigator.userAgent;
if (lsBrowser.indexOf(“MSIE”) >= 0)
{
lsBrowser = “MSIE”;
}
else if (lsBrowser.indexOf(“Firefox”) >= 0)
{
lsBrowser = “Firefox”;
}
else if (lsBrowser.indexOf(“Chrome”) >= 0)
{
lsBrowser = “Chrome”;
}
else if (lsBrowser.indexOf(“Safari”) >= 0)
{
lsBrowser = “Safari”;
}
else if (lsBrowser.indexOf(“Opera”) >= 0)
{
lsBrowser = “Opera”;
}
else
{
lsBrowser = “UNKNOWN”;
}
return lsBrowser;
}
function getBrowserVersion()
{
Search WWH ::




Custom Search