Categories

Friday, April 19, 2024
#919814419350 therichposts@gmail.com
JavascriptJquery

How to disable control u, control s with javascript?

disable control u, control s with javascript

Hello to all, welcome to therichpost.com. In this post, I will tell you How to disable control u, control s with javascript? Some people want to secure their code, even me also so with this javascript code, we can little bit secure our valuable code from copy makers.

Here you can you can check the code to disable control u, control s with javascript:

Here is the code you need to add this into body tag:

<body onkeypress=”return disableCtrlKeyCombination(event);” onkeydown=”return disableCtrlKeyCombination(event);”>

Here is the script code:

<script>
function disableCtrlKeyCombination(e)
{
//List of keys
var forbiddenKeys = new Array(‘u’, ‘s’);
var key;
var isCtrl;
if(window.event)
{
key = window.event.keyCode; //IE
if(window.event.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
else
{
key = e.which; //firefox
if(e.ctrlKey)
isCtrl = true;
else
isCtrl = false;
}
//if ctrl is pressed check if other key is in forbidenKeys array
if(isCtrl)
{
for(i=0; i<forbiddenKeys.length; i++)
{
//case-insensitive comparation
if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
{
//alert(‘Key combination CTRL + ‘+String.fromCharCode(key) +’ has been disabled.’);
return false;
}
}
}
return true;
}
</script>

There are so many tricky code in javascript and I will let you know all. Please do comment if you any query related to this post. Thank you. Therichpost.com

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.