Skip to content

Instantly share code, notes, and snippets.

@Matt-Jensen
Last active December 19, 2015 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Matt-Jensen/5889842 to your computer and use it in GitHub Desktop.
Save Matt-Jensen/5889842 to your computer and use it in GitHub Desktop.
This could be a horrible idea but this is a short function that detects the supported pointer type and returns a string to use with event listeners.
// Determine the supported pointer event, whether click or touch ect.
function supportedClickEvent() {
var supportedEvent = 'click';
if( 'ontouchstart' in window ) {
supportedEvent = 'touchstart';
}
else if( window.navigator.msPointerEnabled ) {
supportedEvent = 'MSPointerDown';
}
else if( 'pointerdown' in window ) {
supportedEvent = 'pointerdown';
}
return supportedEvent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment