Redirect only for desktop device

Viewed 35

I am trying to redirect desktop device changing a script:

if (screen.width <= 699) {
  document.location = "Other URL";
}

699 to major width but doesn't work. Please how can do this redirect? My purpose is do it only for descktop but I have success only with mobile. Aby suggest?

1 Answers

Here is script in ECMA6 [works on modern browsers version]. also redict page for desktop device.

var isMobile = navigator.userAgent.toLowerCase().indexOf('mobile') > -1;
var getChromeVersion = function() {
  var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./);
  return raw ? parseInt(raw[2], 10) : false;
};


console.log('isMobile :' + isMobile)
console.log('getChromeVersion :' + getChromeVersion())

if (isMobile == false) {
// if device is desktop then redirect our page
 window.location.replace("https://maximumroulette.com");
 // OR
 // window.location.href = "https://www.google.com";
}

Related