We don't execute document.execCommand() this time, because it is called recursively.
Hi, folks!
I'm trying to clean paste-data like this:
<textarea id="edit456"></textarea>
var onpaste = function(e) {
e.preventDefault();
var text = e.clipboardData.getData("text/plain");
document.execCommand("insertHTML", false, text);
};
var edit = document.getElementById('edit456');
edit.addEventListener('paste', onpaste);
Then I paste data via context menu (or you can do it on console for tests)
document.execCommand("paste");
and got warning from console: "We don't execute document.execCommand() this time, because it is called recursively."
The data will not be pasted.
I was looking for info on the same console message that's appearing when trying to cut-to-clipboard within a nw app. I came across this link which, though old, may help in your case? They use setTimeout() to get around the issue -- so I don't know if it's a bug or a security "feature".
https://code.google.com/p/chromium/issues/detail?id=363288#c3
@TrevorPT I have tried it, didn't help
It works in my case but I didn't try to set up your code. Where did you invoke the setTimeout, like this?
setTimeout( function () {
document.execCommand("insertHTML", false, text);
}, 0 );
@TrevorPT thank you very much! Found out that setTimeout not necessary - works without it, also helped gui.Clipboard:
var gui = require('nw.gui');
var clipboard = gui.Clipboard.get();
document.execCommand("insertHTML", false, clipboard.get()); //or insertText