我搜索了很多帖子,发现了很多将 iOS 设备重定向到不同页面的脚本。但我不想更改整个页面,只更改一个链接。
整个站点 (www.example.com) 适用于 iOS 设备,包括一个指向基于 Flash 的应用程序页面的链接(在不同的主机上 - app.example.com)。这个特定的应用程序有一个在 iPad 上使用的 iOS 版本。单击链接时,我只是希望将计算机用户发送到 Flash 应用程序页面,将 iPad 用户发送到一个页面(在 www. 上),告诉他们有关 iOS 应用程序的信息。
我设想的是这样的:
如果用户使用的是 iPad,则在头部使用 iOS 检测脚本将“isiPad”变量设置为“true”。然后在 body 中的功能如下:
如果'isiPad'=true,则
<a href="http://www.example.com/useiOSapp.html"> Run the App </a>
否则
<a href="http://app.example.com/flash-app-page.html">Run the App</a>
最佳答案
HTML
<a id="myLink" href="">Run App</a>
Javascript
$(document).ready(function($){
var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
if (agentID) {
$('#myLink').attr('href', 'http://example.com/useiOSapp.html');
}else
{
$('#myLink').attr('href', 'http://example.com/flash-app-page.html');
}
});
关于javascript - 仅针对单个 href 更改检测 iPad(或 iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9184715/