is there a script to detect, if the visitor use iphone (whatever it's browser, may iphone Safari, iPhone for Opera or etc.)?
Then will shutdown some some of my JavaScript.
Thanks...
is there a script to detect, if the visitor use iphone (whatever it's browser, may iphone Safari, iPhone for Opera or etc.)?
Then will shutdown some some of my JavaScript.
Thanks...
<script language="javascript" type="text/javascript">
//This redirects iPhone users to the iPhone-friendly site
if ((navigator.userAgent.indexOf('iPhone') != -1) ||
(navigator.userAgent.indexOf('iPod') != -1)) {
document.location = "http://i.yoursite.com";
}
This script checks for iPhone or iPod in the userAgent and then executes an action. Give this a try.
searching on the net there are two common ways of achieving this. My favorite though is in PHP its just so clean? wow. :D
and in PHP you say
<?php
function isIphone($user_agent=NULL) {
if(!isset($user_agent)) {
$user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
}
return (strpos($user_agent, 'iPhone') !== FALSE);
}
if(isIphone()) {
header('Location: http://www.yourwebsite.com/phone');
exit();
}
// ...THE REST OF YOUR CODE HERE
?>
and in javascript you say
var agent = navigator.userAgent;
var isIphone = ((agent.indexOf('iPhone') != -1) || (agent.userAgent.indexOf('iPod') != -1)) ;
if (isIphone) {
window.location.href = 'http://www.yourwebsite.com/phone';
}
Hope that helps.
PK