I'm trying to disable selection highlighting and the context menu (Copy, Cut, Select All, etc.) of input fields using JavaScript on a Vive Focus VR headset Android WebView.
I've tried the below solutions, but none of them work for the Vive Focus:
Solution #1:
$.fn.extend({
disableSelection : function() {
this.each(function() {
this.onselectstart = function() {
return false;
};
this.unselectable = "on";
$(this).css('-moz-user-select', 'none');
$(this).css('-webkit-user-select', 'none');
});
}
});
$(function() {
$(this).disableSelection();
});
Solution #2:
function disableSelect(el){
if(el.addEventListener){
el.addEventListener("mousedown",disabler,"false");
} else {
el.attachEvent("onselectstart",disabler);
}
}
function enableSelect(el){
if(el.addEventListener){
el.removeEventListener("mousedown",disabler,"false");
} else {
el.detachEvent("onselectstart",disabler);
}
}
function disabler(e){
if(e.preventDefault){ e.preventDefault(); }
return false;
}
Solution #3:
window.oncontextmenu = function () {return false;};
Solution #4:
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'));
}
I posted another question (How to remove selection highlighting for input field in CSS?) related to this about using CSS to achieve this, but unfortunately, it does not disable the selection/context menu on the Vive Focus for input fields.
Could you please help me with this?
Thanks