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 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码