Hey guys I have a project coming up with the following requirements
Create a page that uses JavaScript to determine if the user is viewing the site with a mobile device and changes the stylesheet to display the page appropriately.
For some reason I can't make it work. I don't know how to get the page to run the js function and soon as its opened or how to test it to even see if it was working. The code I have been using is as follows:
<script>
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( isMobile.any() ) alert('Mobile');
};
</script>