I have a small text editor in my home page ( a textarea ) where I can paste text. How can I get this text in a variable before it would be pasted? I know that there is this function:
clipboardData.getData()
but it doesn’t work in Firefox, and I want something for all the browsers.I am using HTML and Javascript.
thanks
The short answer is that in general you can’t get the text before it is pasted. What you can do is what big web-based WYSIWYG editors such as CKEditor and TinyMCE do, which is:
keypressevent handler<div>element off-screen (say at left -1000px) to the document, move the caret to be inside that div, thus effectively redirecting the pasteNote that this will only work for keyboard paste events and not pastes from the context or edit menus. By the time the paste event fires, it’s too late to redirect the caret into the div (in some browsers, at least).