dongpengyu1363 2011-05-08 12: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 14: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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部