clipboardData can contain data in various potential formats. Its possible program will add clipboard data in several formats. To view formats, browse clipboardData.types .
Often the clipboard data contains plain text, and the first type specified in types will be the MIME type "text / plain". If you copy text from tho browser, you will see two types in the list: "text / plain" and "text / html". Depending on which line you go to getData , you may grab plain text or html. It seems that "text" is short for "text / plain", and "url" is short for "text / uri-list".
element.addEventListener('paste', function(event) { var cb = event.clipboardData if(cb.types.indexOf("text/html") != -1) { // contains html var pastedContent = cb.getData("text/html") } else if(cb.types.indexOf("text/html") != -1) { // contains text var pastedContent = cb.getData("text/html") } else { var pastedContent = cb.getData(cb.types[0]) // get whatever it has } // do something with pastedContent })
For more on how to use clipboardData.getData , see the ugly spec .
BT
source share