View Full Version : Change Link by Operating System
CyberScout
05-08-2003, 02:51 PM
This is probably really simple and I just can't find a script for it, but basically what I would like to do is to change a link (HREF) to a different link depending on what operating system they are running.
So the browser does an OS Check, and if the OS = mac then change <a href="main">click here</a> to <a href="mac">click here</a>
Any thoughts would be GREATLY appreciated.
Thanks in advance!
CyberScout
wox3-iO
05-08-2003, 03:04 PM
I feel so tired right now... so here's a helpful link for you:
moock's browser detecting basics (http://www.moock.org/webdesign/javascript/detector/detector-top.html)
Maybe some1 less tired can give a bit better piece of code...
CyberScout
05-08-2003, 03:14 PM
he he, well I know how to detect a browser version. My problem comes in when I try to detect an OPERATING SYSTEM and then based on the OS, change an HREF.
I already have tons of scripts for detecting an OS, but don't know how to add the function of changing an HREF.
Thanks for a speedy response anyway.
And thanks in advance to anyone else who helps. :)
Roy Sinclair
05-08-2003, 03:43 PM
<a href="gohere.htm" id="golink">Go Somewhere</a>
<script>
if (theOSIDetectedInAnotherScript=="OddballOS")
{
document.getElementById("golink").href = "gothere.htm"
}
</script>
CyberScout
05-08-2003, 04:49 PM
Ok, well as it turns out my OS detection script doesn't work as well as I thought, or perhaps I am just combining these two scripts wrong.
Would you (or anyone for that matter) know a good OS Detection script as well as know how to combine that script with the script above?
Thanks in advance, and thanks for the speedy responses
CyberScout
What about something like this
<A HREF="main.html" onClick="if(OS=='mac') this.href='mac.html';">click here</a>
(assuming the var OS has been setup somewhere else)
cheesebagpipe
05-08-2003, 04:59 PM
From javascriptkit (http://www.javascriptkit.com/script/cut22.shtml):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>untitled</title>
<script type="text/javascript" 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>
</head>
<body>
<script type="text/javascript" language="javascript">
var OpSys = checkOS();
document.write('<a href="' + OpSys + '.htm">Operating system</a>');
</script>
</body>
</html>
CyberScout
05-09-2003, 01:38 PM
Cheesebagpipe, that seemed to do the trick. Thanks a lot everyone who worked on this with me.
-CyberScout :thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.