【问题标题】:how do i disable a certain javascript on iphone/ipad or other mobile devices?如何在 iphone/ipad 或其他移动设备上禁用某些 javascript?
【发布时间】:2010-05-02 04:01:17
【问题描述】:
我在 IE 浏览器上得到了这个,
var IE = /*@cc_on!@*/false;
if (IE) {
// IE.
} else {
// Others.
}
但是我如何为 iphone/ipad/mobiledevices 做同样的事情?
(不想重定向到任何移动设备上的另一个页面)
【问题讨论】:
标签:
javascript
iphone
mobile
ipad
mobile-safari
【解决方案1】:
您可能需要检查user agent 字符串,如下所示:
var userAgent = navigator.userAgent;
if (userAgent.match(/iPad/i) || userAgent.match(/iPhone/i)) {
// iPad or iPhone
}
else {
// Anything else
}
【解决方案2】:
这应该有点问题,因为每个应用程序都有自己的 Header。我的 apache 服务器将此作为浏览器获取:[APPNAME]/1.0_CFNetwork/459_Darwin/10.3.0
你可以搜索 Darwin,但我不知道这是否防水。
JS-Snippet 应该是这样的:
if (navigator.userAgent.indexOf("Firefox") != -1)
{
document.write('You're using Mozilla Firefox');
}