How to disable the Ctrl + S (or) Ctrl + C (or) Any Key Using Javascript in HTML

How to disable the Ctrl + S  (or) Ctrl + C (or) Any Key Using Javascript in HTML
How to disable the Ctrl + S (or) Ctrl + C (or) Any Key Using Javascript in HTML

How to disable the Ctrl + S  (or) Ctrl + C (or) Any Key Using Javascript in HTML ?

Example :

Download

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<HTML>
<HEAD>
<TITLE> Welcome Logo samples </TITLE>
<META NAME=”Generator” CONTENT=”EditPlus”>
<META NAME=”Author” CONTENT=””>
<META NAME=”Keywords” CONTENT=””>
<META NAME=”Description” CONTENT=””>

<script language=”JavaScript”>
function disableCtrlKeyCombination(e)
{
//list all CTRL + key combinations you want to disable
var forbiddenKeys = new Array(“a”, “s”, “c”);
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>

</HEAD>

<BODY ¬†onkeypress=”return disableCtrlKeyCombination(event);” onkeydown=”return disableCtrlKeyCombination(event);”>

<CENTER>

<table>
<tr>
<td>Sample-1
</td>
<td>
<img src=”Sample1.jpg” />
</td>
</tr>
<tr>
<td>Sample-2
</td>

<td>
<img src=”Sample2.jpg” />
</td>
</tr>
<tr>
<td>Sample-3
</td>

<td>
<img src=”Sample3.jpg” />
</td>
</tr>
<tr>
<td>Sample-4
</td>

<td>
<img src=”Sample4.jpg” />
</td>

</tr>
</tr>

<tr>
<td>Sample-5
</td>

<td>
<img src=”Sample5.jpg” />
</td>

</tr>
</tr>

<tr>
<td>Sample-6
</td>

<td>
<img src=”Sample6.jpg” />
</td>

</tr>
</tr>

<tr>
<td>Sample-7
</td>

<td>
<img src=”Sample7.jpg” />
</td>

</tr>
</tr>
<tr>
<td>Sample-8
</td>

<td>
<img src=”Sample8.jpg” />
</td>

</tr>
</tr>
</table>
</CENTER>
</BODY>
</HTML>

 

Download

Leave a Reply