Directing mobile users to mobile site

It is becoming increasingly popular to automatically redirect mobile users to a mobile optimised site when accessing a desktop web url. This is usually done server side. For the more advanced browsers, the Safari on iPhone or Androids for example, you can also use a javascript to redirect the user. Such a script could look something like this:

<script language=javascript>
 if((navigator.userAgent.match(/iPhone/i)) || 
    (navigator.userAgent.match(/iPod/i))){
       if(confirm('Hey, is it an apple in your hand? Go to the mobile site?'))
	 location.replace("URL HERE");
  }
</script>

This will create a popup asking the user whether he/she would like to go to the mobile site. Handy stuff.

Comments are closed.