Last active
May 1, 2021 12:16
-
-
Save Dchole/3a0ba4dccb427558558ed85b217d671c to your computer and use it in GitHub Desktop.
Script to alert user what device they are using in raw vanilla JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const BUTTON = document.querySelector("button"); | |
const { userAgent } = window.navigator; | |
// Set device to "mobile" if "Mobi" exists in userAgent else set device to "desktop" | |
const device = userAgent.includes("Mobi") ? "mobile 📱" : "desktop 💻"; | |
BUTTON.addEventListener("click", () => alert(`You are on ${device}`)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment