Pergunta

I designed a theme for mobiles for my website. But I do not know how to "redirect" mobiles visitors to that theme?

What are the available options for my scenario?

Foi útil?

Solução

You can detect and redirect mobile users by using this PHP class

Outras dicas

You can use the media="handheld" attribute when you are specifying your CSS file, so that it would only load for handheld devices, such as mobile phones. But this is becoming redundant nowadays, since android browsers and the iPhone's browser do not identify themseleves as handheld devices, to prevent from being served webpages with minimal formatting.

Take a look at this thread.

To load a custom phone.css for a mobile phone, you can rely on the user's screen width and use a media query.

For example, add this into your <head> section:

<link rel="stylesheet" type="text/css" media="screen and (max-device-width: 480px)" href="phone.css" />

Now, phone.css will load when the screen width of the device is less than 480px.

For a detailed explanation, check out this source.

Hope this helped. :)

You have to check the user agent string of the HTTP request.

Based on that, you can redirect to the corresponding site, or load the right CSS/resource files etc.

If you wish to see the user agent string for your browser, you can go to this site. For example, I'm using Chrome in a Windows 8 PC right now, and my string is:

Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36

I have a plethora of Android devices at home. When browsing with Chrome, they all have basically the same user agent string. The site I linked to also lists the most common ones (check the links in the footer).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top