Jump to content

Redirect mobile devices via HTML5-4

nuribruner's Photo
Posted Nov 28 2011 07:11 PM
4585 Views

Hey guys,

I'm working on a new webpage and would like to keep it as css/javascript/HTNL as possibly, keeping away from say PHP. Now I'll come to my question, how can I redirect mobile devices to another path on my website? Does anyone have any code snipets for the noob ;)

Thanks, nuribruner

Co-Host
The Pear Podcast & Reviews
Nuri R. Bruner
thepearpod@gmail.com
www.thepearpod.com

2 Replies

0
  Altharaz's Photo
Posted Jun 11 2012 08:02 PM

Hi !

If you want definitely to redirect your visitors, you can use this code :
<script language=javascript>
<!--
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
    if (mobile) {  
        document.location = "http://www.yourmobilewebsite.com";  
    }  
-->
</script>

Source : http://localstreamer...-detect-all-mob

However, please put a button to allow people to go back to the normal version of your website.

You can also just use CSS3 features, and use this kind of code to use the stylesheet according to the device :
<link rel="stylesheet" href="screen.css" media="screen"/>
<link rel="stylesheet" href="handheld.css" media="handheld"/>

Source : http://www.designyou...g-mobile-users/

I'd rather go for the second option, but it's up to you!
0
  mhalverson's Photo
Posted Jun 14 2012 09:13 PM

I'm not sure how it works off the top of my head in this case, but some webservers (APACHE) for example, are able to redirect based on the headers sent.

For apache look up how to use mod_redirect or mod_rewrite. You can even set it up so that the user isn't even aware that they are being served a different page if you want. This will work without using PHP (which I would recommend against in this case anyways, unless you need to build dynamic pages) and will work even if the user has javascript turned off. It is the "user-agent" header that you will be using.