Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cut And Paste Disable

Status
Not open for further replies.

prudhivi

Programmer
Apr 15, 2002
3
US
Hi,
I have a form in which i want to disable the functionality for using CUT and PASTE using either by CTRL C and CTRL V or by MOUSE right click.
I tried using comapring event.controlkey and event.keyCode but it looks like in IE4 and above there is a different character code .
Can any one help me out where i can get this CONTROL KEY CODE List for IE4.

Thanks
 
Ask IE 4 --

Code:
  var aK = new Array(2)
  aKClr()

function getKeyCode(state) {
  aK[state] = event.keyCode
}

function aKShow() {
  alert("keyDown "+aK[0]+"\nkeyPress "+aK[1]+"\nkeyUp "+aK[2])
  aKClr()
}

function aKClr() {
  for (var i = 0; i < aK.length; i++) {
    aK[i] = -1
    }
}

called by --

Code:
<body onload=&quot;document.all.pcIn.focus();&quot;>
Type a key
<input type=&quot;text&quot; id=&quot;pcIn&quot; maxlength=&quot;1&quot; size=&quot;1&quot;
  onkeydown=&quot;getKeyCode(0);&quot; onkeypress=&quot;getKeyCode(1);&quot;
  onkeyup = &quot;getKeyCode(2);aKShow();this.value = '';&quot; />

CTL-C returns 67 for keydown/up, ignores keypress. CTL-V returns 86, ignores keypress (and pastes first char from clipboard). You may be asking too much of IE 4 as Cut/Paste functionality may be inherited from Windows, there whether you like it or not.
 
var aK = new Array(3);
aKClr();

function getKeyCode(state) {
aK[state] = event.keyCode
}

function aKShow(from) {

if((aK[0] == 65 && aK[1] == 97 && aK[2] == 17) || (aK[0] == 65 && aK[1] != -1 && aK[2] == 65)) {
aKClr();
}
if((aK[0] == 67 && aK[1] == -1 && aK[2] == 17) || (aK[0] == 67 && aK[1] !=-1 && aK[2] == 67)) {
aKClr();
}
if ((aK[0] == 86 && aK[1] == -1 && aK[2] == 17)) {
aKClr();
from.value=&quot;&quot;
}
return true;
}


function aKClr() {
for (var i = 0; i < aK.length; i++) {
aK = -1
}
aK[3]=-1
}


Hi,
I used your code and modify little bit. what happens here is when you to first time time CTRL A and CTRL C and CTRL V it is working . but next time the event is not firing . so i modify the same.
Secondly the counter should be made as -1 for 0,1 and 2nd array . now it is working
I am trying even Mouse right click but it is working if i keep alert message inside the condition . see this function

function rightClick() {

if (navigator.appName == 'Netscape' && (event.which == 3 || event.which == 2)) {alert(&quot;No&quot;);return false};
if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {alefrt(&quot;no&quot;);return false;}
}

If i delete the alert message it is not working. can you tell me why?

 
prudhivi,

make sure you only delete &quot;alert(&quot;No&quot;)&quot; and not &quot;alert(&quot;No&quot;);return false;&quot; ... the &quot;return false;&quot; part is what makes it work. ======================================

if (!succeed) try++
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top