jquery.nocopypaste.js 823 B

12345678910111213141516171819202122232425
  1. /**
  2. * When included, this snippet prevents contextual menus and keystrokes that
  3. * make it possible to cut/paste/copy text from the page.
  4. * This is useful for very secure exams.
  5. * @author Alberto Torreblanca
  6. */
  7. $(document).ready(function(){
  8. $(document).on("cut copy paste contextmenu",function(e) {
  9. e.preventDefault();
  10. });
  11. $(document).keydown(function(e) {
  12. var forbiddenKeys = new Array('c', 'x', 'v', 'p', 's');
  13. var keyCode = (e.keyCode) ? e.keyCode : e.which;
  14. var isCtrl;
  15. isCtrl = e.ctrlKey
  16. if (isCtrl) {
  17. for (i = 0; i < forbiddenKeys.length; i++) {
  18. if (forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
  19. return false;
  20. }
  21. }
  22. }
  23. return true;
  24. });
  25. });