samedi 12 septembre 2020

send user to another page when device is mobile

i'm trying to make a system when the user device is mobile send them to a mobile page with javascript but isn't works

JavaScript code

let mobile = navigator.userAgent.match(/Mobi/i) ? true : false ;
  if(mobile == "true"){
     window.location.assign("indexm.html");
      console.log("is " + mobile);
      
  }
  if(mobile == "false"){
      window.location.assign("https://microsft.com");
      console.log("is " + mobile);
  }
  else{
      window.location.assign("indexm.html");
      console.log("is other device"  + mobile);
  }

when user open the page from mobile the mobile variable is true but don't send the user to the other page




Aucun commentaire:

Enregistrer un commentaire