Code Snippets Gallery
Redirect Mobile Devices
<script type="text/javascript">
<!--
if (screen.width <= 699) {
document.location = "mobile.html";
}
//-->
</script>“mobile.html” would be replaced with the location of wherever your mobile version resides. This technique could be adapted to load an alternate stylesheet as well.
For iPhones/iPods Specifically
<script language=javascript>
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("http://url-to-send-them/iphone.html");
}
-->
</script>
Nice and concise! thanks
Thanks a lot @anon. I find it very useful also.
no safari
What if mobile phone can not use JavaScript?
But and devices that do not work with javascript?
in the iPad/iphone version.
Is it suppose to say…
“navigator.userAgent.match(/iPod/i” or
“navigator.userAgent.match(/iPad/i” ????
This works great!
One thing: Once a mobile user logs onto the site it takes them to the mobile site. I want to let them be able to go to the full-version site. But of course when they click on the link, it redirects them to the mobile site.
Any help is appreciated!