window.getSelection return html [duplicate]
问题 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: