execcommand

window.getSelection return html [duplicate]

霸气de小男生 提交于 2019-11-26 14:18:08
问题 This question already has an answer here : HTML of selected text (1 answer) Closed 6 years ago . function selected() { var selObj = window.getSelection(); } This function returns selected text from a webpage. How do return the html of a selected area. Is this possible to do with an <img> and an <a> tag? Here's the list of functions: https://developer.mozilla.org/Special:Tags?tag=DOM&language=en 回答1: The following will do this in all major browsers and is an exact duplicate of this answer:

Cross-browser Save As .txt

假装没事ソ 提交于 2019-11-26 11:31:51
问题 Is there a JavaScript library that allows to save strings as txt files, and works cross-browser? In the past, I have been using Downloadify, but I am looking at another option for a couple reasons: I hope to find a pure JavaScript solution, without the need for Flash it seems that Downloadify is not updated anymore (no update in the past 18 months) I am experiencing an issue with Downloadify in IE 9, where strings are cut off 回答1: As far as I know, the only way is to use data: URLs to force a

document.execCommand() FontSize in pixels?

点点圈 提交于 2019-11-26 09:50:59
问题 How can I change font size to 30px (for example) using document.execCommand ? This: document.execCommand(\"fontSize\", false, \"30px\"); doesn\'t work, because in 3rd argument of the function execCommand, it only allows me to input a value between and including 1 to 7. 回答1: It's a limitation of the FontSize command. There are various options I can think of: You could use a CSS class instead and use the CSS class applier module of my Rangy library; You could use a hacky method, such as calling

Javascript trick for &#39;paste as plain text` in execCommand

我只是一个虾纸丫 提交于 2019-11-26 04:30:56
问题 I have a basic editor based on execCommand following the sample introduced here. There are three ways to paste text within the execCommand area: Ctrl + V Right Click -> Paste Right Click -> Paste As Plain Text I want to allow pasting only plain text without any HTML markup. How can I force the first two actions to paste Plain Text? Possible Solution: The way I can think of is to set listener for keyup events for ( Ctrl + V ) and strip HTML tags before paste. Is it the best solution? Is it