"prevent default press but not default drag in ios mobilesafari?" Code Answer


success: prevent "default press" behavior entirely through css instead of preventdefault. this answer was provided by safari technologies evangelist vicki murley over here (registration required)

i see in your post that you say your ultimate goal is that:

"we never want the default mobilesafari press behavior of "copy image" or selecting text."

these behaviors can be disabled in css (+ one bonus property, since people often want to turn off the highlight if they're turning off these other behaviors):

/* behavior */
-webkit-user-select: none;                /* disable cut copy paste */
-webkit-touch-callout: none;              /* disable callout, image save panel */
-webkit-tap-highlight-color: transparent; /* "turn off" link highlight */

commentary: we assumed that safari's press behavior was event-based, not driven by css. calling preventdefault ontouchstart does cancel the press behavior (which is what led us astray, really), but that seems to be an unintended side-effect. really, mobile safari does not execute a "press event" so much as "css on press".

disabling the press behavior with css has allowed us to once again call preventdefault only where and when we actually need it.

By Nick Ragaz on March 21 2022
Only authorized users can answer the Search term. Please sign in first, or register a free account.