0

是否可以根据用户是使用 javascript 的 mac 还是 PC 来更改链接的目标?

举个例子:Apple 网站允许下载 Quicktime,但它“知道”您使用的是 Mac 还是 PC,并将您定向到相关页面。

这样做的背景/原因:我为某人建立了一个网站,他们在那里有许多音频和视频文件。理想情况下,他们想要它,这样如果用户在 Mac 上,它将下载文件的快速版本,但如果他们在 PC 上,它将下载 Windows Media Player 文件。

干杯

克里斯

4

3 回答 3

1

您可以检查 UserAgent 标头以区分 Mac 和 PC 浏览器。

于 2009-09-15T19:05:54.530 回答
0

是的。这不是万无一失的,但可以做到。是检测您的操作系统的 Javascript 示例。您可以根据结果简单地选择显示不同div或类似的内容。

于 2009-09-15T19:06:53.967 回答
0

这是一个例子

<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>

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

于 2009-09-15T19:07:40.453 回答