How to disable CTRL+U button using Javascript.

0
56
views

I have already covered this post on but it didn’t go quite right. What I did on that was, I disabled the key ‘U’ so that users can’t use the ‘Ctrl+U’ shortcut key for viewing the page source along with that, I also disabled the ‘P’ button in order to disable the shortcut keys for printing ‘Ctrl+P’ but it turned out to be a useless method for disabling these two shortcut keys. If you look at the comments on that post, you will find out why I’m calling that a useless method.
After using my previous script, I noticed that my visitors were unable to type ‘U’ and ‘P’ while writing a comment and I realized that after my visitors started complaining about it, even the that who copies from my blog which is funny. So, I had to remove the script from my blog and start looking for a better idea to disable those shortcut keys and here I’m with that better idea. The script I’m sharing in this post will disable the shortcut key ‘Ctrl+U’ only if it’s pressed together. Which means, unlike my previous method, your visitors will be able to type any key without any difficulty.

Below is the script and all you got to do is, place the script above the closing </head> tag. It will work fine on any platform. Whether it’s a blogger, WordPress or your self made Webpage.


<script type='text/javascript'> 
window.addEventListener("keydown",function (e) {
var key;
if(window.event){
key = window.event.keyCode;
if(e.ctrlKey && (key == 85 )){
return false;
}else{
return true;
}
}else{
key = e.which;
if(e.keyCode == 123 || ( e.ctrlKey && ( key == 85))){
e.preventDefault();
return false;
}else{
return true;
}
}
});
</script>

The reason most people disables such shortcut keys is that of the content stealer but the bad thing is, no matter how hard you try, there will always be another way for the content stealer to steal your content. So, it’s better to just go on with your writings and forget about them. Those blogs don’t last for long, either they will delete it themselves or Google will kick them out from search results.

Also prepard more JavaScript or jquery interview question .

Previous articleBEST JAVASCRIPT QUSETIONS 2018
SHARE

LEAVE A REPLY

Please enter your comment!
Please enter your name here