My code looks okay and works fine. But when I force desktop site on chrome Android, it gets the function and executes the function supposed to work on only desktop or not mobile/tablet devices. Why the navigator.userAgent.match is working like desktop in mobile? Please help me.
JAVASCRIPT
function upme()
{
var isdesk = !(navigator.userAgent.match(/iphone|ipod|android|blackberry|opera|mini|windows phone|palm|smartphone|mobile|phone|iemobile|ipad|webos|xoom|sch-i800|playbook|tablet|kindle/i));
// event listeners
window.addEventListener('resize', relod, false);
function relod()
{
if(isdesk)
{
location.reload();
}
}
window.addEventListener('scroll', doso, false);
window.addEventListener('resize', doso, false);
function doso()
{
if(window.matchMedia("(min-width: 765px)").matches && isdesk)
{
document.getElementById("last-dab").style.visibility = "visible";
}
}
}
So the function should be working on desktop devices for the isdesk condition check. But when forcing desktop site option on chrome breaks everything by doing jittery behavior and the function gets done/executed in mobile, which should not happen. What is wrong?
Can I detect if the force desktop site is enabled or not using javascript. If so please provide a JavaScript solution.