iPhone, iPad, iPod Detection in Javascript
Saturday, February 26, 2011 EST (Updated on: Thursday, July 21, 2011 EDT)
by: Eric Potvin
If you develop website for Apple iPhonetm or Apple iPod Touchtm or an Apple iPadtm, you might want the user to be redirected to another page.
The version of Safari Web Browser used by the Apple iPod Touchtm is the same as the version used by the Apple iPhonetm or an Apple iPadtm, but carries a different user agent string.
Here's the JavaScript code you need to use in your landing page:
<script type="text/javascript">
if(navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i)) {
// some code
window.location = "/iphone.html";
}
if(navigator.userAgent.match(/iPad/i)) {
// some code
window.location = "/ipad.html";
}
</script">
In the file iphone.html or ipad.html (filename from the JavaScript above), you will need to put the following:
<meta name="viewport" content="width=device-width, user-scalable=no" />or
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
Be the first to reply!
Share this article: