Click here to Skip to main content
15,903,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Clipboard in which current copied value is stored.
I can get the current value which is currently in clipboard using javascript and i am using chrome browser but i am unable to modify the clipboard value or clean clipboard data.because i ahve to design a system in which once i paste the copied value ,it should be deleted or remove from clipboard. when i try to paste again that value ,it should not be pasted.
Help

What I have tried:

document.addEventListener("paste", function (e) {
var clipText = e.clipboardData.getData('Text');

clipText= clipText.toUpperCase();


console.log(e.target.id);

if(temp2==clipText)
count=count+1;

e.preventDefault();



if(clipText!=null && count==0)
{

e.target.value = clipText ;
temp2=clipText;

}
else
if(temp2!=clipText ){

e.target.value = clipText ;
temp2=clipText;

}else{
if(temp2==clipText && count>0 )
{

e.target.value = "" ;

}
}
return false;
});
Posted
Updated 5-Feb-18 3:37am

1 solution

There is no method to detect that another application has pasted data from the clipboard. Once data has been put on the clipboard, the data is owned by the system and can be queried by any other application.

All you can do is clearing the clipboard when your application is pasting. But you should not do so because the data may be from any application and the users might want to paste it multiple times.

You might want to provide the data by Drag & Drop instead because that is doing what you want: Once data are dropped or the drag operation is cancelled, the data are destroyed.
 
Share this answer
 
Comments
poojakumawat1 6-Feb-18 2:21am    
there is only one page in which i have to clear clipboard when the same string gets pasted.
For e.g i have copied a string and i m trying to paste that string in one textbox and it should get pasted. then i try to paste that string in another textbox ,it should not be pasted.but if i again copy that string ,it should be pasted in textbox.
So all i want to clear my clipboard after pasting value
document.addEventListener("paste", function (e) {
e.target.value = e.clipboardData.getData('Text');

//Clear logic of clipboard in javascript
});
i could try this: e.clipboardData.setData('Text','');,clipboardData.cleardata();
but this is not supporting in chrome.
HELP
Jochen Arndt 6-Feb-18 2:52am    
To clear the clipboard you have to set new data. This can be done with document.execCommand('copy') which requires an active selection (e.g. from a hidden textbox). Examples can be found by searching for "javascript copy to clipboard":
https://clipboardjs.com/
https://ourcodeworld.com/articles/read/143/how-to-copy-text-to-clipboard-with-javascript-easily

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900