根据用户是否拥有 Mac 或 PC 更改链接目标

发布于 2024-08-04 09:25:01 字数 265 浏览 7 评论 0原文

是否可以根据用户使用的是 Mac 还是 PC 来更改链接的目的地?

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

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

干杯

克里斯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦行七里 2024-08-11 09:25:01

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

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

尘世孤行 2024-08-11 09:25:01

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

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.

软的没边 2024-08-11 09:25:01

示例

<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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文