I'm trying to put together a function so that when a user clicks on an HREF (not a form) it will evaluate their platform and take them to the appropriate html page.
Here is the evaluation code in the HEAD:
<SCRIPT language="JavaScript"><!--
function platformSniffer(macURL,os2URL,linuxURL,winURL) {
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('webtv')==-1));
var is_mac = (agt.indexOf("mac")!=-1);
var is_os2 = ((agt.indexOf("os/2")!=-1) ||
(navigator.appVersion.indexOf("OS/2")!=-1) ||
(agt.indexOf("ibm-webexplorer")!=-1));
var is_linux = (agt.indexOf("inux")!=-1);
var is_win = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
var is_win16 = ((agt.indexOf("win16")!=-1) ||
(agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
(agt.indexOf("windows 16-bit")!=-1) );
var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
(agt.indexOf("windows 16-bit")!=-1));
var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
var is_win32 = (is_win95 || is_winnt || is_win98 ||
((is_major >= 4) && (navigator.platform == "Win32")) ||
(agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));
if (is_mac) { // Macintosh
location.href = macURL;
} else if (is_os2) { // OS2
location.href = os2URL;
} else if (is_linux) { // Linux
location.href = linuxURL;
} else if (is_win || is_win95 || is_win98 || is_winnt || is_win31 || is_win32 || is_win16) {
location.href = winURL; // Windows
}
}
//--></SCRIPT>
And here is my HREF:
<A HREF=http://www.webdeveloper.com/forum/archive/index.php/"#" onclick="platformSniffer('intro_m.htm','intro.htm','intro.htm','intro.htm')">
Can anyone tell me why this won't work?? Thanks for any help and assistance.
Here is the evaluation code in the HEAD:
<SCRIPT language="JavaScript"><!--
function platformSniffer(macURL,os2URL,linuxURL,winURL) {
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
&& (agt.indexOf('webtv')==-1));
var is_mac = (agt.indexOf("mac")!=-1);
var is_os2 = ((agt.indexOf("os/2")!=-1) ||
(navigator.appVersion.indexOf("OS/2")!=-1) ||
(agt.indexOf("ibm-webexplorer")!=-1));
var is_linux = (agt.indexOf("inux")!=-1);
var is_win = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
var is_win16 = ((agt.indexOf("win16")!=-1) ||
(agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
(agt.indexOf("windows 16-bit")!=-1) );
var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
(agt.indexOf("windows 16-bit")!=-1));
var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
var is_win32 = (is_win95 || is_winnt || is_win98 ||
((is_major >= 4) && (navigator.platform == "Win32")) ||
(agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));
if (is_mac) { // Macintosh
location.href = macURL;
} else if (is_os2) { // OS2
location.href = os2URL;
} else if (is_linux) { // Linux
location.href = linuxURL;
} else if (is_win || is_win95 || is_win98 || is_winnt || is_win31 || is_win32 || is_win16) {
location.href = winURL; // Windows
}
}
//--></SCRIPT>
And here is my HREF:
<A HREF=http://www.webdeveloper.com/forum/archive/index.php/"#" onclick="platformSniffer('intro_m.htm','intro.htm','intro.htm','intro.htm')">
Can anyone tell me why this won't work?? Thanks for any help and assistance.