Want to Disable Long press on all images in the webpage. Could anyone recommend me a simple way to do it.Also I'm a newbie to Java Script.
I've tried "pointer-events:none" in CSS.But it disabled clicking too. I've used the images as a Hyperlink so clicking can't be avoided.
function absorbEvent_(event) {
var e = event || window.event;
e.preventDefault && e.preventDefault();
e.stopPropagation && e.stopPropagation();
e.cancelBubble = true;
e.returnValue = false;
return false;
}
function preventLongPressMenu(node) {
node.ontouchstart = absorbEvent_;
node.ontouchmove = absorbEvent_;
node.ontouchend = absorbEvent_;
node.ontouchcancel = absorbEvent_;
}
function init() {
preventLongPressMenu(document.getElementById('theimage'));
}
Source: https://newbedev.com/disabling-the-context-menu-on-long-taps-on-android