JavaScript of the Week -

They have: 62 posts

Joined: Dec 1998

The JavaScript of the Week is intended to help you understand and implement basic scripts on your web site...

Browser Redirect

This script will load a specific page based on the browser type and version.

Place the following script in the head element of your document:

<Script>
<!--
var browser=navigator.appName + " " + navigator.appVersion;
var getkey=browser.substring(0, 12);

// Load page according to browser
function loadPage()
{

if (browser.substring(0, 8)=="Netscape") //Netscape
{
if (getkey=="Netscape 4.0") //4.x
window.location.href="filename.htm";
if (getkey=="Netscape 3.0") //3.x
window.location.href="filename.htm";
if (getkey=="Netscape 2.0") //2.x
window.location.href="filename.htm";
}

if (browser.substring(0, 9)=="Microsoft") //MSIE
{
if (browser.substring(0, 29)=="Microsoft Internet Explorer 4") //4.x
window.location.href="filename.htm";
if (browser.substring(0, 29)=="Microsoft Internet Explorer 3") //3.x
window.location.href="filename.htm";
if (browser.substring(0, 29)=="Microsoft Internet Explorer 2") //2.x
window.location.href="filename.htm";
}

if ( (browser.substring(0, Cool!="Netscape") && (browser.substring(0, 9)!="Microsoft") ) //Unknown Browser
window.location.href="filename.htm";
}

// -->
</Script>

Add an onLoad trigger to your body tag:

<BODY onLoad="loadPage()">

Your basic page here...

Until the next Script of the Week, post your webmaster related question to the Webmaster Forums.

------------------
Jeffrey Ellison
[email protected]
www.eons.com - Free Online Tools for Webmasters

[This message has been edited by Jeffrey Ellison (edited February 04, 1999).]

They have: 62 posts

Joined: Dec 1998

Alternately, you may want to redirect or perform some other function based on the client operating system (OS). Here is the code you need to determine the clients OS:

Detect Client Operating System

Place in head element of your document:

<SCRIPT LANGUAGE="JavaScript">
<!--
function checkOS() {
if(navigator.userAgent.indexOf('IRIX') != -1)
{ var OpSys = "Irix"; }
else if((navigator.userAgent.indexOf('Win') != -1) &&
(navigator.userAgent.indexOf('95') != -1))
{ var OpSys = "Windows95"; }
else if(navigator.userAgent.indexOf('Win') != -1)
{ var OpSys = "Windows3.1 or NT"; }
else if(navigator.userAgent.indexOf('Mac') != -1)
{ var OpSys = "Macintosh"; }
else { var OpSys = "other"; }
return OpSys;
}
// -->
</SCRIPT>

Elsewhere in the document:

<SCRIPT LANGUAGE="JavaScript">
<!--
var OpSys = checkOS();
document.write(OpSys);
// -->
</SCRIPT>

Check back often for new scripts...

------------------
Jeffrey Ellison
[email protected]
www.eons.com - Free Online Tools for Webmasters

[This message has been edited by Jeffrey Ellison (edited February 05, 1999).]

They have: 62 posts

Joined: Dec 1998

Redirect by Day of Week

Simply paste this code into the head element of your document to redirect a visitor to a particular page based on the day of the week:

<SCRIPT LANGUAGE="JavaScript">
<!--

function initArray() {
this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++)
this[i+1] = initArray.arguments[i];
}

var dayArray = new;
initArray("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

var today = new Date();
var day = dayArray[today.getDay()+1];

if (day == "Monday") window.location = "monday.htm"
if (day == "Tuesday") window.location = "tuesday.htm"
if (day == "Wednesday") window.location = "wednesday.htm"
if (day == "Thursday") window.location = "thursday.htm"
if (day == "Friday") window.location = "friday.htm"
if (day == "Saturday") window.location = "saturday.htm"
if (day == "Sunday") window.location = "sunday.htm"

//-->
</SCRIPT>

------------------
Jeffrey Ellison
[email protected]
http://www.eons.com - Free Online Tools for Webmasters

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.