Created
April 26, 2019 12:55
-
-
Save tigran-sn/91561cbc6c716ec6de9ddaa2c5367102 to your computer and use it in GitHub Desktop.
Paste only plain text (JavaScript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isIE(){ | |
| return ua.indexOf('MSIE ') > 0 || ua.indexOf('Trident/') > 0; | |
| } | |
| document.querySelector("[contenteditable]").addEventListener("paste", function (e) { | |
| e.preventDefault(); | |
| let text = ""; | |
| if (isIE()) { | |
| text = window.clipboardData.getData('text'); | |
| e.target.innerText += text; | |
| } else { | |
| text = e.clipboardData.getData('text/plain'); | |
| document.execCommand("insertHTML", false, text); | |
| } | |
| if (text !== null && text.trim().length > 0) { | |
| $(this).siblings(/* Fake Placeholder */).hide(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment