Sunday 28 April 2013

Redirect a webpage depending on device?

Hi all,

This article is to redirect a web page depending on the device, your are accessing the web page..

this redirection can be done using the UserAgent of the device,
The user agent of your device(desktop,Laptop,Ipad,etc.,) can be known from here

this is a simple java script method that will check the useragent of the device..

Simply put the below code in tour head tag of your web page..

<script type="text/javascript">

  if ( (navigator.userAgent.indexOf('iPad') != -1) ) {
    document.location = "http://www.apple.com/ipad/";
  }
else   if ( (navigator.userAgent.indexOf('iPod') != -1) ) {
    document.location = "http://www.apple.com/ipod/";
  }
else if ( (navigator.userAgent.indexOf('iPhone') != -1) ) {
    document.location = "http://www.apple.com/iphone/";
  }

else if ( (navigator.userAgent.indexOf('Windows') != -1) ) {
    document.location = "http://www.microsoft.com/";
  }


</script>


here, By using we can redirect to any web page depending on the device, for example you can see the bank sites, where if you request a bank site via mobile, the website will be of different format, that is done by the same User agent..

thanks
shameer ali shaik

No comments:

Post a Comment