I followed this question JavaScript get clipboard data on paste event (Cross browser) to get the pasted data from the clipboard, but I used jquery instead. Now that I got the data, I removed all html tag. But I don't know how to paste it.
element
is a contenteditable div
element.on('paste', function (e) {
var clipboardData, pastedData;
e.preventDefault();
// Get pasted data via clipboard API
clipboardData = e.clipboardData || window.clipboardData || e.originalEvent.clipboardData;
pastedData = clipboardData.getData('Text').replace(/<[^>]*>/g, "");
// How to paste pasteddata now?
console.log(pastedData);
});
Might be easier to let the paste proceed and update element immediately after. Would depend on use case also as cursor position could be lost this way
I found the answer and I am gonna share it. In order to sanitize the clipboard from html tags, you should paste this:
Credit: l2aelba
Well, it depends on what element are you going to paste in. You could use jQuery or native Javascript to achieve!
Maybe like
$(targetNode).append(pastedData)
ordocument.getElementById('targetNode').innerText = pastedData