Sunday, July 12, 2020
therichposts@gmail.com
JavascriptJquery

How to disable control u, control s with javascript?

disable control u, control s with javascript

Views

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

Ajay Malhotra
the authorAjay Malhotra
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 2, Angular 6, Angular 7, Angular 8, Angular 9, Angular 10 Nodejs, laravel, Codeigniter, Shopify, Squarespace, Jquery, Google Map Api, Vuejs, Reactjs, Bigcommerce etc.

Leave a Reply

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