Created
January 25, 2017 22:32
-
-
Save hannesl/42a35904a4e15f3b4211cb967ddac8fb to your computer and use it in GitHub Desktop.
Detect browser capabilities reliably with 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
document.addEventListener("DOMContentLoaded", function () { | |
var touchDetect = function () { | |
document.documentElement.classList.add("has-touch"); | |
document.removeEventListener("touchstart", touchDetect); | |
}; | |
var hoverDetect = function () { | |
document.documentElement.classList.add("has-hover"); | |
document.removeEventListener("mouseenter", hoverDetect); | |
}; | |
document.addEventListener("touchstart", touchDetect); | |
document.addEventListener("mouseenter", hoverDetect); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment