Main Page

Safari

Because you are only be scripting for two browsers, by default you should have an error message telling
users that they are using the wrong browser. This displays if there is no JavaScript support, as well as if
the wrong browser or wrong operating system is being used. Here’s a sample:
<html>
<head>
<title>Login</title>
<script type=”text/javascript” src=”detect.js”></script>
</head>
<body>
<form method=”post” action=”DoLogin.jsp”>
<div style=”border: 2px dashed blue; background-color: #dedede; height:
300px; padding: 10px”>
<div id=”divError” style=”position: absolute; left: 20px; top:
100px; “>
This Web application requires one of the following:
<ul>
<li>Internet Explorer 5.5 or higher for Windows</li>
<li>Mozilla 1.0 or higher for Unix</li>
<li>Safari 1.0 or higher for Macintosh</li>
</ul>
</div>
</div>
</form>
</body>
</html>
The highlighted section of code contains the actual error message. Note that the entire error message is
contained within a
<div/>
named
divError
. Also note that
divError
has an absolute position. This is
important because the login form lies directly over the error message. However, the login form is invisi-
ble at load time and is only shown if appropriate. Before getting to that, add the code for the login form
right after the error message:
<html>
<head>
<title>Login</title>
<script type=”text/javascript” src=”detect.js”></script>
</head>
<body>
<form method=”post” action=”DoLogin.jsp”>
<div style=”border: 2px dashed blue; background-color: #dedede; height:
300px; padding: 10px”>
<div id=”divError” style=”position: absolute; left: 20px; top:
100px; “>
This Web application requires one of the following:
<ul>
<li>Internet Explorer 5.5 or higher for Windows</li>
<li>Mozilla 1.0 or higher for Unix</li>
<li>Safari 1.0 or higher for Macintosh</li>
</ul>
</div>
253
Browser and Operating System Detection
11_579088 ch08.qxd 3/28/05 11:38 AM Page 253


JavaScript EditorFree JavaScript Editor     Ajax Editor


©