Skip to content

Instantly share code, notes, and snippets.

@hannesl
Created January 25, 2017 22:32
Show Gist options
  • Save hannesl/42a35904a4e15f3b4211cb967ddac8fb to your computer and use it in GitHub Desktop.
Save hannesl/42a35904a4e15f3b4211cb967ddac8fb to your computer and use it in GitHub Desktop.
Detect browser capabilities reliably with JS
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