1
votes

I have a requirement where a text copied onto the clipboard, has to be transformed into some other text before it gets pasted. E.g on button click I do a clipboard copy programmatically and some text like "Before Change" gets copied onto the clipboard. The paste event which I have tied to my editor cannot change the clipboard data and its always the data existing on the clipboard ("Before Change") that gets copied.

$("#Editor1").on("paste", createIncludedScriptPath);
function createIncludedScriptPath(e) {
    var pastedData = e.originalEvent.clipboardData.getData('text');
    var path = createPath(pastedData);
    textToCopy = "." + " " + "'" + path + "'";
    copyTextToClipboard(textToCopy);
}

Here, in the above code, I am trying to get the existing clipboard data, change it and copy the changed data on the clipboard. However, it is always the old data i.e. (in the pastedData variable) which gets pasted.

I learnt, that in the clipboard paste API, you cannot reset the clipboard.

How do I update the clipboard data, so that the updated data gets eventually pasted?

1
the best option is to modify the data Before copying to clipboard.Naman Kheterpal
I cannot, because I am deriving some information based on where it is going to be pastedpuneet
ok. So you can make the change in above evnt handler function and manually put .value of editable box. Don't forget to put preventDefault()Naman Kheterpal
It worked!, Thanks Namanpuneet

1 Answers

2
votes

You could set the editor content directly and call e.preventDefault();

I think updating the clipboard data will not work.