Redirect Mobile Devices

Posted by & filed under Tips.

Javascript

1. Detect and redirect based on screen size

Below code will detect device’s screen size and if it’s less than 699 pixels, it will redirect it to your mobile enabled site (in this example m.yoursite.com).

Place the below code between <head> and </head> tags of your page. And replace “http://m.yoursite.com” to your own URL.

2. Detect and redirect if the device agent matches iPhone or iPod

Below code will specifically look out for iPhone and iPod devices, once matches, it will redirect them to your mobile enabled site (in this example m.yoursite.com). 

Place the below code between <head> and </head> tags of your page. And replace “http://m.yoursite.com” to your own URL.

PHP

Open your header.php file, go to top of the document and hit <enter> to make an empty line before all the HTML codes start. Copy and paste the following code.

Don’t forget to replace “http://m.yoursite.com” to your own URL.

 Others

If you want to use other scripts, you may check out http://detectmobilebrowsers.com

Share this with your friends

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>