0

How to get clipboard text and html without Flash in Firefox when user pressed "Ctrl+V", I can move focus into a textarea to get the paste text, or move focus to a contenteditable div to get the paste html, but how to get them both?

If I move focus to a contenteditable div to get the paste html, and then extract the text from the innerHTML, it seems that text is not exactly the same with paste event text

virsir
  • 15,159
  • 25
  • 75
  • 109

2 Answers2

1

Do you mean something like this demo. When you paste into the contenteditable and hit go, it'll give you both the text and HTML of what you pasted.

input = document.getElementById('a'); // is contenteditable
input.textContent; // plain text
input.innerHTML; // html
sachleen
  • 30,730
  • 8
  • 78
  • 73
1

This has been asked before, and the answer here seems to be popular: JavaScript get clipboard data on paste event (Cross browser)

Community
  • 1
  • 1
The Muffin Man
  • 19,585
  • 30
  • 119
  • 191
  • I checked that link, but do not get my answer. – virsir Sep 10 '12 at 03:02
  • You asked how to get what's in the clipboard when the user uses the operating system default paste method. OK. You cant directly access the clipboard, but you can capture the control + v key event and then get the content of the currently focused textbox. – The Muffin Man Sep 10 '12 at 03:15