Sample Scripting used for the Web Presence project
This script determine the type of browser the site is being viewed with and then displays an appropriate message or redirects the browser to an alternative page.
<!--********This JavaScript detects the browser type and
version***********-->
<script LANGUAGE="JavaScript"><!--
//Set up some variables and get ua (user agent) info.
var browser = "unknown"
var version = 0
var ua = window.navigator.userAgent
//Are we in Microsoft Internet Explorer or Netscape Navigator?
if (ua.substring(0,7) == "Mozilla") {
if (ua.indexOf("MSIE") > 0) {
browser = "Microsoft"
}
//Now check the browser version number.
if (ua.indexOf("4.") > 0) {
version = 4
}
if (ua.indexOf("3.") > 0) {
version = 3
}
}
//--></script>
<!--************************End of detection
script*************************-->
<!--*******************This JavaScript detects the users *******************-->
<!--***********system time and displays a time of day greeting*******************-->
<script LANGUAGE="JavaScript">
<!--
{
var now = new Date();
var hours = now.getHours();
document.write("<center><h2>");
if (hours < 12) {
document.write("Good morning! </h2></center>");
}
else if (hours < 17) {
document.write("Good afternoon! </h2></center>");
}
else {
document.write("Good evening! </h2></center>");
}
}
//-->
</script>
<!--************************ End of greeting script
*************************-->
<div ID="IE4" align="center" style="display:none">
<p>This site has a Macromedia Flash 4.0 introduction. If you do not have Flash
please
download it from Macromedia by clicking on the button below. </p>
</div>
<div ID="IE" align="center" style="display:none">
<p>This site has a Macromedia Flash 4.0 introduction and uses technology that
reqires
Internet Explorer Ver 4 or above. You can download the latest versions of Internet
Explorer and Macromedia Flash by clicking on the buttons below. </p>
</div>
<div ID="Netscape" align="center"
style="display:none">
<p>It has been determined that you are viewing the this site with a Netscape browser
or
another non Explorer browser. This site has a Macromedia Flash 4.0 introduction and uses
technology that requires Internet Explorer 4 or above. You can download the latest
versions of Internet Explorer and Macromedia Flash by clicking on the buttons below.
</p>
</div>
<!--*************This JavaScript uses the information from the
******************-->
<!--********detection script and either displays the apropriate text or *********-->
<!--****************sends the user to an alternative
page*************************-->
<script LANGUAGE="JavaScript"><!--
//If Microsoft Internet Explorer 4 is in use
if (browser == "Microsoft" && version == 4) {
document.all.IE4.style.display=""
}
//If Microsoft Internet Explorer 3 is in use
if (browser == "Microsoft" && version == 3) {
document.all.IE.style.display=""
}
//If Netscape Navigator 4 is in use -Redirect the browser to an
alternative page
if (browser == "unknown") {
location.href="NetscapeUser.htm"
}
//--></script>
<!--****************************** End of
script****************************-->