Redirect Mobile Devices

<script type="text/javascript">

if (screen.width <= 768) {

document.location = "tablet_site.html";

}

else if (screen.width <= 320){

document.location = "mobile_site.html";

}

</script>

“mobile_site.html” and “tablet_site.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.

but for Apple devices, they have some specific things to be coded 

<script language=javascript>

if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {

   location.replace("http://url-to-send-them/iphone.html");

}

</script>

for wordpress templating, we code like the below

@media screen and (max-width:320px)

{

h1 {

color: #ffb400;

}

}

@media screen and (min-width:321px) and (max-width:768px)

{

h1 {

color:#0096ff;

}

}

@media screen and (min-width:769px)

{

h1 {

color: #693573;

}

}

and for drupal, we go like this

name = Responsive template

description = An example of using Media Queries in Drupal7

core = 7.x

stylesheets[all][] = css/reset.css

stylesheets[all][] = css/main.css

stylesheets[(min-width: 480px)][] = css/480.css

stylesheets[(min-width: 768px)][] = css/768.css

stylesheets[(min-width: 1024px)][] = css/1024.css

stylesheets[(min-width: 1280px)][] = css/1280.css

here we should define all the css mentioned in the above code (” 480.css ”, “768.css”, “1024.css” and “1280.css

finally, what if our browser doesnt support javascript ???????

USE PHP!!! 😀

I use this

you’ll have to change the extension on your page from .html or .htm to .php so the server knows to process the script. Also this needs to be before the <html tag – ie the first line on the page. To add a device just add it to the if statement under the mobileDevice() function

function mobileDevice()

{

$type = $_SERVER['HTTP_USER_AGENT'];

if(strpos((string)$type, “Windows Phone”) != false || strpos((string)$type, “iPhone”) != false || strpos((string)$type, “Android”) != false)

return true;

else

return false;

}

if(mobileDevice() == true)

header(‘Location: mobile.html‘);

Hahaha.. thats all dear 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s