Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is some code I found somewhere but I lost the actual link and this seems to work. </p> <p><a href="http://jsfiddle.net/Y4BBq/" rel="noreferrer">http://jsfiddle.net/Y4BBq/</a></p> <pre><code>&lt;html lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;title&gt;The serialized HTML of a selection in Mozilla and IE&lt;/title&gt; &lt;script type="text/javascript"&gt; function getHTMLOfSelection () { var range; if (document.selection &amp;&amp; document.selection.createRange) { range = document.selection.createRange(); return range.htmlText; } else if (window.getSelection) { var selection = window.getSelection(); if (selection.rangeCount &gt; 0) { range = selection.getRangeAt(0); var clonedSelection = range.cloneContents(); var div = document.createElement('div'); div.appendChild(clonedSelection); return div.innerHTML; } else { return ''; } } else { return ''; } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div&gt; &lt;p&gt;Some text to &lt;span class="test"&gt;test&lt;/span&gt; the selection on. Kibology for &lt;b&gt;all&lt;/b&gt;&lt;br /&gt;. All &lt;i&gt;for&lt;/i&gt; Kibology. &lt;/p&gt; &lt;/div&gt; &lt;form action=""&gt; &lt;p&gt; &lt;input type="button" value="show HTML of selection" onclick="this.form.output.value = getHTMLOfSelection();"&gt; &lt;/p&gt; &lt;p&gt; &lt;textarea name="output" rows="5" cols="80"&gt;&lt;/textarea&gt; &lt;/p&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <blockquote> <p><img src="https://i.stack.imgur.com/gjGGD.png" alt="enter image description here"></p> </blockquote> <p>There are some issues with the code (I tested with safari) where it doesn't return the exact selection.</p> <blockquote> <p><img src="https://i.stack.imgur.com/q5vJq.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/rFMSs.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/M0yf0.png" alt="enter image description here"></p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload