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

iScroll.js and iOS browser detection - show the iScroll.js file only to iPad/iPhone

本文关键字:iScroll js iPhone 显示 文件 iPad iOS 浏览器 检测 仅向      更新时间:2023-09-26

我创建了一个页面,该页面使用固定的页眉和页脚位置,并且必须在iPad/iPhone上运行。我正在使用iScroll.js(http://cubiq.org/iscroll-4)在iPad/iPhone上滚动页面。但是,我需要此脚本仅在iOS上运行(页面是简单的HTML页面),例如:http://projects.klavina.com/iscroll/

问题:我想只向iOS设备显示JS(在HTML文档的头部区域)(类似于IE的条件注释)。我该怎么做?这在Javascript中可能吗?如果没有,我可以使用 PHP 吗?我不做任何后端编程,但我相信如果你指出我正确的方向,我可以弄清楚。

谢谢!

如 Safari 网页内容指南中所述,您可以使用用户代理来确定您是否在 iOS 设备上。你可以在JavaScript或PHP中轻松测试它。下面是一个 JavaScript 示例:

userAgent = window.navigator.userAgent;
if(/iPhone/.test(userAgent) || /iPod/.test(userAgent) || /iPad/.test(userAgent)) {
    // load iScroll here
}