Posted By

apphp-snippets on 05/26/17


Tagged

click right block javascritp


Versions (?)

Blocking Right-Click in Browser with JavaScript


 / Published in: JavaScript
 

URL: http://www.apphp.com/index.php?snippet=javascript-blocking-right-click

This snippet code allows you to prevent the viewer from being able to right-click on your page. This can discourage the average user from borrow images or code from your site.

  1. <script type="text/javascript">
  2. function f1() {
  3. if(document.all) { return false; }
  4. }
  5. function f2(e) {
  6. if(document.layers || (document.getElementById && document.all)) {
  7. if(e.which==2 || e.which==3) { return false; }
  8. }
  9. }
  10. if(document.layers) {
  11. document.captureEvents(Event.MOUSEDOWN);
  12. document.onmousedown = f1;
  13. }
  14. else {
  15. document.onmouseup = f2;
  16. document.oncontextmenu = f1;
  17. }
  18. document.oncontextmenu = new function("return false");
  19. </script>

Report this snippet  

You need to login to post a comment.