Advertisement
pusatdata

Kode Lengkap JS Disable Klik Kanan

Apr 10th, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. /*!
  2. * Font Awesome Free 5.9.0 by @fontawesome - https://fontawesome.com
  3. * License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License)
  4. */
  5. (function () {
  6. /*
  7. https://www.computerhope.com/javascript/disable-right-click.htm
  8. */
  9. var isNS = (navigator.appName == "Netscape") ? 1 : 0;
  10. if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
  11.  
  12. function mischandler(){
  13. return false;
  14. }
  15.  
  16. function mousehandler(e){
  17. var myevent = (isNS) ? e : event;
  18. var eventbutton = (isNS) ? myevent.which : myevent.button;
  19. if((eventbutton==2)||(eventbutton==3)) return false;
  20. }
  21.  
  22. document.oncontextmenu = mischandler;
  23. document.onmousedown = mousehandler;
  24. document.onmouseup = mousehandler;
  25.  
  26. /*
  27. https://mycyberuniverse.com/developing/disabling-right-clicking-by-using-javascript.html
  28. */
  29. /**
  30. * Disable right-click of mouse, F12 key, and save key combinations on page
  31. * By Arthur Gareginyan (https://www.arthurgareginyan.com)
  32. * For full source code, visit https://mycyberuniverse.com
  33. */
  34. window.onload = function() {
  35. document.addEventListener("contextmenu", function(e){
  36. e.preventDefault();
  37. }, false);
  38.  
  39. document.addEventListener("keydown", function(e) {
  40. //document.onkeydown = function(e) {
  41. // "I" key
  42. if (e.ctrlKey && e.shiftKey && e.keyCode == 73) {
  43. disabledEvent(e);
  44. }
  45.  
  46. // "J" key
  47. if (e.ctrlKey && e.shiftKey && e.keyCode == 74) {
  48. disabledEvent(e);
  49. }
  50.  
  51. // "S" key + macOS
  52. if (e.keyCode == 83 && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
  53. disabledEvent(e);
  54. }
  55.  
  56. // "U" key
  57. if (e.ctrlKey && e.keyCode == 85) {
  58. disabledEvent(e);
  59. }
  60.  
  61. // "F12" key
  62. if (event.keyCode == 123) {
  63. disabledEvent(e);
  64. }
  65. }, false);
  66.  
  67. function disabledEvent(e){
  68. if (e.stopPropagation){
  69. e.stopPropagation();
  70. } else if (window.event){
  71. window.event.cancelBubble = true;
  72. }
  73.  
  74. e.preventDefault();
  75. return false;
  76. }
  77. };
  78.  
  79. /*
  80. https://www.howtogeek.com/251807/how-to-enable-pasting-text-on-sites-that-block-it/
  81. */
  82. var allowPaste = function(e){
  83. e.stopImmediatePropagation();
  84. return false;
  85. };
  86. document.addEventListener('paste', allowPaste, false);
  87.  
  88. /*
  89. https://www.itzgeek.com/web/disable-right-click-html-script.html
  90. */
  91. //Disable right mouse click Script
  92. //By Geek Site.in
  93. function clickIE4(){
  94. if (event.button==2){
  95. return false;
  96. }
  97. }
  98.  
  99. function clickNS4(e){
  100. if (document.layers||document.getElementById&&!document.all){
  101. if (e.which==2||e.which==3){
  102. return false;
  103. }
  104. }
  105. }
  106.  
  107. if (document.layers){
  108. document.captureEvents(Event.MOUSEDOWN);
  109. document.onmousedown=clickNS4;
  110. }
  111. else if (document.all&&!document.getElementById){
  112. document.onmousedown=clickIE4;
  113. }
  114.  
  115. document.oncontextmenu=new Function("return false")
  116. }());
  117. raw
  118. formatted
  119.  
  120.  
  121. ==================
  122. simpan file ini dalam dot js
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement