Question
Accenture
GB
Last activity: 19 Nov 2018 9:58 EST
How to disable Mouse middle click (middle button) across all browsers?
Hi,
Greetings. There is a code to disable right click but i am interested in disabling mouse middle click and we use edge, i am not sure if edge supports auxclick, can some one with similar requirement let me know if you have a solution?
Regards,
Bharat
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Accenture
GB
We have replaced all "#" within an anchor tag with javascript:void(0) null, that prevented the middle click of an event
Pegasystems Inc.
US
You could leverage a similar approach seen here and listen for the middle click button event, and just return or preventDefault() or something equivalent to prevent the middle click from executing its default action.
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_event_mouse_button
Accenture
GB
I have the following code, right click is disabled but mouse wheel click is still not disabled, i am trying it on edge
<script>
function clickIE() {
if (document.all) {
return false;
}
}
function clickNS(e) {
if (document.layers || (document.getElementById && !document.all)) {
if (e.which == 2 || e.which == 3) {
e.preventDefault();
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown = clickNS;
}
else {
document.onmouseup = clickNS;
document.oncontextmenu = clickIE;
}
document.oncontextmenu = new Function("return false")
</script>
Pegasystems Inc.
US
Shouldn't you be monitoring for button click 1 per the W3 school example?
Accenture
GB
It is capturing the event (click 1) but not able to prevent the events from propagating especially in edge
Pegasystems Inc.
US
Hi ,You can use the following code in userWorkForm . I have tested it and its working in my case .
Hi ,You can use the following code in userWorkForm . I have tested it and its working in my case .
<script>
document.attachEvent('onmousewheel', function(e){
if (!e) var e = window.event;
e.returnValue = false;
e.cancelBubble = true;
return false;
}, false);
</script>
-
Luan Pontes
Accenture
GB
Hi,
Thanks, I am trying on Edge, did the above code work in edge?
Accenture
GB
Is that the full code? its not even going into the function, i have added an alert to check
<script>
document.attachEvent('onmousewheel', function(e){
if (!e) var e = window.event;
alert("test");
alert(e);
e.returnValue = false;
e.cancelBubble = true;
return false;
}, false);
</script>
Pegasystems Inc.
US
You can create a function and place it in that . you can try placing that in your function , clickNS(e) {}
Accenture
GB
This is not working even though it is capturing the event, the links are still being opened in a new tab,I am using Edge
Accepted Solution
Accenture
GB
We have replaced all "#" within an anchor tag with javascript:void(0) null, that prevented the middle click of an event
-
Raju Botu