After many days of searching and testing I cannot solve this mystery of why a simple mobile redirect is not redirecting. I have tested several variations from across the web with no avail. If anyone has a moment to look at what I have, please do. Thanks in advance.
My goal: Redirect site to mobile site upon detection of user agent.
My code is below. NOTE: if I change
if(isMobile.any()) {
to
if(isMobile) {
the desktop browser will redirect the site.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<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()) {
{ window.location = 'http://www.briggsmechanical.com/mobile/index.html';
}
}
</script>