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 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化