Blocking Right-Click in Browser with JavaScript


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.