iScroll.js and iOS browser detection - show the iScroll.js file only to iPad/iPhone
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 docume开发者_StackOverflownt) 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!
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
}
精彩评论