I am trying to paste data from clipboard to textarea
<textarea id="mytextarea"></textarea>
<script type="text/javascript">
tinymce.init({
selector: '#mytextarea',
plugins: "paste",
paste_data_images: true
});
function handlePaste (e) {
var clipboardData, pastedData;
// Stop data actually being pasted into div
e.stopPropagation();
e.preventDefault();
// Get pasted data via clipboard API
clipboardData = e.clipboardData || window.clipboardData;
pastedData = clipboardData.getData('Text');
// Do whatever with pasteddata
var paste = document.getElementById('mytextarea');
paste.innerText = pastedData;
}
document.getElementById('mytextarea').addEventListener('mouseenter', handlePaste);
</script>
But nothing happening no error. I found many answers but i none solved my problem
I believe in Chrome you can only access clipboardData when handling the paste event. So you would have to be listening for that event to access the clipboardData.
Change your event listener to listen for the paste event, and then you can do whatever you want with the clipboardData in the handler:
document.getElementById('mytextarea').addEventListener('paste', handlePaste);
You can see this in action in the following fiddle:
https://jsfiddle.net/x3v8bhhr/
I added a second textarea. When you try to paste into the first textarea, the clipboardData is intercepted, and placed in the second textarea instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With