2

Is it possible to disable an specific key combination? CTRL + U for example?

I don't want to allow the user to press ctrl + u in order to see my javascript code. I only had disabled the left click but i would like more "protection".

Thanks!

chepe263
  • 2,774
  • 22
  • 38
  • 4
    you can never stop the user from seeing your code, try to make a good website instead – Ibu Mar 20 '12 at 18:24
  • 2
    What's to stop them from clicking "View -> Source" – Mike Robinson Mar 20 '12 at 18:28
  • 1
    If the user really wanted to see your code, they could disable JavaScript and then use the right mouse button or press ctrl + u. You cannot hide your code in the front end. – philnash Mar 20 '12 at 18:29
  • even if right click is disabled and the shortcut is disabled they can still view source through the menu. If you had a way to disable that they could just download it and look at it. You could uglify it so it's harder to read though: http://marijnhaverbeke.nl/uglifyjs – JKirchartz Mar 20 '12 at 18:33

3 Answers3

2

This will only offer so much protection, if the user knows his\her way around the browser they would be able to see your javascript from say the web developer tools and many many other ways. Remember the information is downloaded to your computer so eventually they can find the files.

​$(document).on('keydown',function(e){
    if( e.ctrlKey === true && e.which === 85 )
        return false; 
}); ​​​​​
aziz punjani
  • 25,586
  • 9
  • 47
  • 56
0

You'll never stop users being able to view source on a site - plus it goes against the open nature of the web. I wouldn't waste your time on it, put those efforts into making stuff people can use rather than preventing them seeing what you're doing.

danblundell
  • 1,443
  • 12
  • 7
0

You can't prevent people from looking at your javascript code. Developers (the only folks who really want to look at it) will find ways to see it, no matter what you do.

Instead if you want to protect it, make it hard to understand when they do see it. The easiest way is to obfuscate it. Minifying does a reasonable job of making javascript hard to understand. But check out this SO question for more ideas. How can I obfuscate (protect) JavaScript?

Community
  • 1
  • 1
Leopd
  • 41,333
  • 31
  • 129
  • 167