仅为iOS设备加载JS脚本? [英] Loading JS script for only iOS devices?

查看:150
本文介绍了仅为iOS设备加载JS脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个我在网站上使用的jQuery脚本,允许iPhone / iPad / iPod上的固定位置背景图像。然而,它似乎与我在网站上使用的另一个脚本冲突,全屏放大背景图像。幸运的是,他们彼此独立,我不需要冲突的背景图像脚本在iOS设备上工作,反之亦然。

I have a jQuery script I'm using on a site to allow fixed position background images on iPhone/iPad/iPod. However it seems to be clashing with another script I am using on the site that enlarges background images full screen. Luckily they're independent of each other, I don't need the clashing background image script to work on iOS devices and vice versa.

有没有办法我可以专门目标IOS设备提供JS文件?我最初考虑使用某种IF语句并在窗口大小上进行操作,但开始变得有点复杂并影响其他非IOS设备。它只需要运行这样的东西...

Is there a way I can specifically target IOS devices to serve a JS file? I initially thought about using some kind of IF statement and doing it on window size but that started to get a bit complicated and affects other non-IOS devices. It just needs to run something like this...

...如果IOS设备然后加载scroll.js

..."if IOS device then load scroll.js"

我知道设备/浏览器嗅探是不受欢迎的,但我想不出另一种解决这个问题的方法。

I know device/browser sniffing is frowned upon but I can't think of another way around this problem.

推荐答案

您可以使用Mobile Safari用户代理字符串来检测移动safari服务器端,请参阅:如何使用PHP检测Mobile Safari服务器端?

You can use the Mobile Safari user agent string to detect mobile safari server-side, see: How do I detect Mobile Safari server side using PHP?

您也可以在JavaScript中执行此操作:

You can also do this in JavaScript:

if(navigator.userAgent.match(/(iPhone|iPod|iPad)/i))

参见 iPhone&使用JavaScript进行iPod检测以获取更多信息。

这篇关于仅为iOS设备加载JS脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆