Forum Moderators: open
I am trying to prevent a user from pasting text into a layer via the Filemenu system on IE via: Edit -> Paste
I have managed to prevent this using Ctrl + V by capturing the key events. And have prevented right clicking and pasting by using a dhtml right click script which replaces the menu.
With IE's filemenu I am able to perform an action when pasting occurs by adding:
onpaste="function();" to the layer tag
But i cannot prevent it from pasting. I thought that by adding:
return false;
to this function that it would cancel it but it still pastes the text. This is how i prevented the use of Ctrl+V.
Any help would be much appreciated
Thanks
Dan.
// Use this function as the onpaste event handler for a field to ensure that the correct
// data type is being pasted.
function screenPaste(oField,sType)
{
event.returnValue=false;
var checkText=window.clipboardData.getData("Text");
switch(sType)
{
case 'date':
if(isValidDate(checkText))
oField.value=checkText
else
alert('Pasted value must be a valid date.');
break;
case 'real':
case 'integer':
if(!isNaN(checkText))
oField.value=checkText
else
alert('Pasted value must be a valid number')
break;
default:
break;
}
return;
}
An example of use would be:
<form>
<input type="text" name="SomeDate" onpaste="screenPaste(this,'date');"/>
</form>