views:

111

answers:

3

Hi

Is it possible to change the destination of a link based on whether the user has a mac or a PC using javascript?

To give an example: The Apple website allows download of Quicktime but it "knows" whether you are using a mac or a pc and directs you to the relevant page.

Background/Reason for doing this: I have built a website for someone and they have a number of audio and video files on there. Ideally they want it so that if the user is on a mac it will download a quicktime version of the file but if they are on a PC it will download a Windows Media Player file.

Cheers

CHRIS

+1  A: 

You can check the UserAgent header to tell Mac and PC browsers apart.

Developer Art
You can't be 100% sure from the User-Agent header, as this can be faked.
system PAUSE
Sure you can't. But there are no alternatives either that will give you a 100% accuracy.
Developer Art
A: 

Yes. It's not foolproof, but can be done. Here's a sample of Javascript detecting your OS. You could simply opt to display a different div or something similar depending on the result.

Andrew Flanagan
A: 

Here is an example

<html>
<head>
<script type="text/javascript">
function yourOS() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("win") != -1) {
    return "Windows";
} else if (ua.indexOf("mac") != -1) {
    return "Macintosh";
} else if (ua.indexOf("linux") != -1) {
    return "Linux";
} else if (ua.indexOf("x11") != -1) {
    return "Unix";
} else {
    return "Computers";
}
}
</script>
<body>
<h1>Welcome to GiantCo Computers</h2>
<h2>We love 
<script type="text/javascript">document.write(yourOS())</script>
<noscript>Computers</noscript>
Users!</h2>
</body>
</html>

from http://www.java2s.com/Code/JavaScript/Development/Getusersoperatingsysteminformation.htm

ldog
LOL "We love Computers Users!"
system PAUSE
That is really helpful guys, at least i now know it is possible to do. Now all i need to do is work out how to get it to link to a diffrent page rather than just return a text result.Cheers CHRIS
Chris Davies