<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Basic mobile device JavaScript (jQuery) detection</title>
<!-- NOTE: You require both the jQuery core plugin and the jQuery.cookie.js plugin (code pasted in, below) -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
/* Cookie plugin - Copyright (c)2006 Klaus Hartl (stilbuero.de). Dual licensed under the MIT and GPL licenses:
http://www.opensource.org/licenses/mit-license.php.
http://www.gnu.org/licenses/gpl.html */
jQuery.cookie=function(name,value,options){if(typeof value!='undefined'){options=options||{};if(value===null){value='';options.expires=-1;}var expires='';if(options.expires&&(typeof options.expires=='number'||options.expires.toUTCString)){var date;if(typeof options.expires=='number'){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expi res=';expires='+date.toUTCString();}var path=options.path?';path='+(options.path):'';var domain=options.domain?';domain='+(options.domain):'';var secure=options.secure?';secure':'';document.cookie=[name,'=',encodeURIComponent(value),expires,path,domain,secure].join('');}else{var cookieValue=null;if(document.cookie&&document.cookie!=''){var cookies=document.cookie.split(';');for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+'=')){cookieValue=decodeURIComponent(cookie.substring( name.length+1));break;}}}return cookieValue;}};
/* Cookie plugin, ends */
function checkForHandhelds(){
var redirectURL = "http://www.google.co.uk/";
var uagent = navigator.userAgent.toLowerCase();
function isHandheld(){//return boolean
return (
(navigator.platform.indexOf("iPhone") != -1) ||
(navigator.platform.indexOf("iPod") != -1) ||
(navigator.platform.indexOf("iPad") != -1) ||
(uagent.search("symbian") != -1) ||
(uagent.search("android") != -1) ||
(uagent.search("windows ce") != -1) ||
(uagent.search("blackberry") != -1) ||
(uagent.search("palm") != -1) ||
(navigator.platform.indexOf("Win32") != -1)
);
}
if( $.cookie('handheld_redirect') == null ){//first visit: redirect IF a modern handheld
if(isHandheld()){//is handheld & set cookie to remember, then redirect
$.cookie("handheld_redirect", "true");//$.cookie("handheld_redirect", "true", { path: '/' });
window.location = redirectURL;
}else{
$.cookie("handheld_redirect", "false");
}
}
else if ($.cookie("handheld_redirect") === "true"){//= true, is handheld
window.location = redirectURL;
}
else if ($.cookie("handheld_redirect") === "false"){//prefers std site
//do nothing
}
}
$(document).ready(function(){
$.cookie("handheld_redirect", null);//uncomment to clear cookie
checkForHandhelds();
});
</script>
</head>
<body>
<p>The page.</p>
</body>
</html>