Reputation: 9
<script src="https://cdnjs.cloudflare.com/ajax/libs/UAParser.js/0.7.19/ua-parser.min.js"></script>
<script>
var ua = new UAParser();
var result = ua.getResult();
console.log(result.device);
</script>
This code gets the name of the device used by a user and displays it in the console. How do I use that information to display a different webpage depending on the device used? If the device is not a mobile device it doesn't display anything in the console. I only want it to go to a different page when it is a mobile device. I need this so I can show a mobile version of my website when the user is using a mobile device.
(Code is not mine got it from here: https://codewithmark.com/mobile-detect)
Upvotes: -1
Views: 77
Reputation: 9
if (result.device.model != undefined){document.location="https://google.com";}
Upvotes: -1