dongpengyu1363 2011-05-08 20:26
浏览 112
已采纳

iScroll.js和iOS浏览器检测 - 仅向iPad / iPhone显示iScroll.js文件

I've created a page that uses fixed positioning for header and footer and has to work also on iPad/iPhone. I'm using iScroll.js (http://cubiq.org/iscroll-4) for scrolling the page on iPad/iPhone. However, I need this script to work only on iOS (pages are simple HTML pages), example: http://projects.klavina.com/iscroll/

Question: I would like to show the JS (in the head area of the HTML document) only to iOS devices (something like Conditional Comments for IE). How can I do that? Is this possible with Javascript? If not, can I use PHP? I don't do any back-end programming, but I believe I could figure that out if you point me in the right direction.

Thank you!

  • 写回答

1条回答 默认 最新

  • doubiaokai4998 2011-05-08 22:49
    关注

    As detailed in the Safari Web Content Guide, you can use the user agent to determine if you are on an iOS device. You can easily test this in either JavaScript or PHP. Here is a JavaScript example:

    userAgent = window.navigator.userAgent;
    if(/iPhone/.test(userAgent) || /iPod/.test(userAgent) || /iPad/.test(userAgent)) {
        // load iScroll here
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题