I have a requirement for my web app to allow the user to "Print Selected Only". In other words, a user selects text and potentially images and then clicks this option. I've seen examples of getting selected text with Javascript, but haven't found a solution for getting the selected html itself.
As an example if I have a document like so:
<html>
<head>
</head>
<body>
<p>A bunch of text</p>
<img src="someimage.jpg" />
<p>Even more text</p>
</body>
</html>
If user highlights the image and the second paragraph, I'd want the javascript to return:
<img src="someimage.jpg" />
<p>Even more text</p>
Is this possible and how would one go about doing it?
Edit: I ended up going with a js library called Rangy for this.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…