Forum Moderators: open

Message Too Old, No Replies

Preventing Paste of Text from IE's Filemenu

         

2e1fmo

4:38 pm on Apr 14, 2005 (gmt 0)

10+ Year Member



Hi

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.

orion_rus

7:08 pm on Apr 14, 2005 (gmt 0)

10+ Year Member



May be just open a new window without menu and close this window, and file menu would be off?
Good luck to you!

john_k

7:27 pm on Apr 14, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the onpaste event. Here is a function that I use to ensure pasted values match the expected data type.


// 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>

2e1fmo

10:37 am on Apr 15, 2005 (gmt 0)

10+ Year Member



John K - thankyou very much for your help, the line : event.returnValue=false; is exactly what i was after to cancel the paste.

Thanks for both replies.