How to disable Ctrl+U using Javascript

Debakant Mohanty

I just want to disable Ctrl+U and Ctrl+C event. The primary purpose of doing this is, preventing users from downloading any image or copying content from my website easily i.e. pressing Ctrl+U for viewing my webpage's source code or pressing Ctrl+C for copying content directly from my webpage.

Currently, I am using this piece of code but it disables my entire keyboard

 <script>
    /*function check(e)
    {
    alert(e.keyCode);
    }*/
    document.onkeydown = function(e) {
            if (e.ctrlKey && (e.keyCode === 67 || e.keyCode === 86 || e.keyCode === 85 || e.keyCode === 117)) {//Alt+c, Alt+v will also be disabled sadly.
                alert('not allowed');
            }
            return false;
    };
    </script>
Debakant Mohanty

This is finally what I got to disable Ctrl+U:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
document.onkeydown = function(e) {
        if (e.ctrlKey && 
            (e.keyCode === 67 || 
             e.keyCode === 86 || 
             e.keyCode === 85 || 
             e.keyCode === 117)) {
            return false;
        } else {
            return true;
        }
};
$(document).keypress("u",function(e) {
  if(e.ctrlKey)
  {
return false;
}
else
{
return true;
}
});
</script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to disable Ctrl+Shift+U?

From Dev

How to Disable the CTRL+P using javascript or Jquery?

From Dev

How Can I Disable the Global Shortcut CTRL + SHIFT + U in Linux Mint?

From Dev

How to hide CTRL+U View source & disable right click and text copy?

From Dev

how to disable right click, f12(debug) and ctrl+s in asp.net application using javascript or jquery

From Dev

want to disable whole keyboard using javascript start key not disabled not even ctrl+d

From Dev

want to disable whole keyboard using javascript start key not disabled not even ctrl+d

From Dev

How to disable the back button in the browser using JavaScript

From Dev

How to Disable a button using php and javascript

From Dev

How to Disable a button using php and javascript

From Dev

How To disable or banishing html element using Javascript

From Dev

How do you disable click events from the contextmenu event when using Ctrl+Click in Safari for Mac?

From Dev

How to disable ctrl+v (paste) function in a JSF page ?. I am using primefaces component.

From Dev

How to disable Ctrl + Shift + C shortcut in Firefox?

From Dev

How to disable ctrl + space event in Netbeans

From Dev

How to disable ctrl-n with AutoHotkey?

From Dev

How to permanently disable Ctrl-s in terminal?

From Dev

How to disable stuck ctrl key in software/memory?

From Dev

How to disable CTRL ALT key on windows 7?

From Dev

How to disable Ctrl+Shift+C in Firefox

From Dev

disable textbox using javascript

From Dev

enable and disable using javascript

From Dev

How to disable Utility Manager (Windows Key + U)

From Dev

How to disable mouseover event from everywhere using javascript/jquery?

From Dev

How disable a field if other field is chosen using Django or JavaScript?

From Dev

How to disable actions on a webpage for first mouse click using javascript?

From Dev

how to display date difference using javascript and disable old dates

From Dev

How to disable full keyboard keys using javascript or jquery?

From Dev

How to disable or hide the native player in IOS, using Jquery / Javascript?

Related Related

  1. 1

    How to disable Ctrl+Shift+U?

  2. 2

    How to Disable the CTRL+P using javascript or Jquery?

  3. 3

    How Can I Disable the Global Shortcut CTRL + SHIFT + U in Linux Mint?

  4. 4

    How to hide CTRL+U View source & disable right click and text copy?

  5. 5

    how to disable right click, f12(debug) and ctrl+s in asp.net application using javascript or jquery

  6. 6

    want to disable whole keyboard using javascript start key not disabled not even ctrl+d

  7. 7

    want to disable whole keyboard using javascript start key not disabled not even ctrl+d

  8. 8

    How to disable the back button in the browser using JavaScript

  9. 9

    How to Disable a button using php and javascript

  10. 10

    How to Disable a button using php and javascript

  11. 11

    How To disable or banishing html element using Javascript

  12. 12

    How do you disable click events from the contextmenu event when using Ctrl+Click in Safari for Mac?

  13. 13

    How to disable ctrl+v (paste) function in a JSF page ?. I am using primefaces component.

  14. 14

    How to disable Ctrl + Shift + C shortcut in Firefox?

  15. 15

    How to disable ctrl + space event in Netbeans

  16. 16

    How to disable ctrl-n with AutoHotkey?

  17. 17

    How to permanently disable Ctrl-s in terminal?

  18. 18

    How to disable stuck ctrl key in software/memory?

  19. 19

    How to disable CTRL ALT key on windows 7?

  20. 20

    How to disable Ctrl+Shift+C in Firefox

  21. 21

    disable textbox using javascript

  22. 22

    enable and disable using javascript

  23. 23

    How to disable Utility Manager (Windows Key + U)

  24. 24

    How to disable mouseover event from everywhere using javascript/jquery?

  25. 25

    How disable a field if other field is chosen using Django or JavaScript?

  26. 26

    How to disable actions on a webpage for first mouse click using javascript?

  27. 27

    how to display date difference using javascript and disable old dates

  28. 28

    How to disable full keyboard keys using javascript or jquery?

  29. 29

    How to disable or hide the native player in IOS, using Jquery / Javascript?

HotTag

Archive