JavaScript Code for Redirect Mobile Users to mobile Website

Leave a Comment
Below is the JavaScript code for redirect mobile users like iPhone, iPad, Android, BlackBerry, Windows mobile Java OS Mobile and many more.


<script type="text/javascript">
var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }
};
<!--
  //  if (screen.width <= 700) {
//        window.location = "http://studyoverflow.org/mobile/";
//    }
//-->
if( isMobile.any() )
{
 window.location = "http://studyoverflow.org/mobile/";
}
else if(screen.width <= 700)
{
window.location = "http://studyoverflow.org/mobile/";
}
</script>

0 comments:

Post a Comment