我在一个网站上有一个链接,使用jQuery在弹出框中打开一个iFrame。如下所示,jQuery脚本仅将此函数应用于具有特定属性'id=calcPop‘的链接。
<a href="calculator.html" id="calcPop">Click here</a>它在所有计算机上都很好用,但在移动设备上却有很大的缺陷。有没有一种方法可以检测用户是否在移动设备上,然后将其更改为没有“id”属性?
发布于 2011-04-12 02:55:31
如果你不能使用像PHP这样的服务器端语言,那么只需使用JS删除ID -如果你有jQuery,下面这样的代码就可以解决这个问题:
$("#calcPop").attr("id", "");检测你是否在移动设备上是相当复杂的,因为有很多移动设备。
你可以使用类似这样的东西:
var isMobile = navigator.userAgent.match(/Mobile/i) != null;要在UA中找到与Mobile相匹配的东西(将与iPod/iPad/iPhone相匹配),不确定其他内容,您必须检查。
把它们放在你的document.ready闭包中:
var isMobile = navigator.userAgent.match(/Mobile/i) != null;
if (isMobile) {
$("#calcPop").attr("id", "");
}在PHP中,你可以这样做:
<?php
$isMobile = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'Mobile');
if ($isMobile) {
$id = "calcPop";
} else {
$id = "";
}
?>
<a href="calculator.html" id="<?= $id ?>">Click here</a>https://stackoverflow.com/questions/5624380
复制相似问题