I have a web application(build with knockout using chrome). I want to disable right click but I tried many ways but it still do not work. How to do it?
Asked
Active
Viewed 776 times
-1
-
yes. i use this way. thankz – Chhornkimchheng Apr 20 '17 at 08:44
1 Answers
1
This code will disable the right click.
Add the following code in script tag - at the end of your HMTL body
If you want to disable the right click of for an element just change the document.querySelector('body');
to document.querySelector('#YOUelementIDhere');
(function () {
var blockContextMenu, myElement;
blockContextMenu = function (evt) {
evt.preventDefault();
};
myElement = document.querySelector('body');
myElement.addEventListener('contextmenu', blockContextMenu);
})();

cpap
- 82
- 1
- 4