Note that there are some explanatory texts on larger screens.

plurals
  1. POgetSelection() not working for <iframe> in IE
    primarykey
    data
    text
    <p>Leading on from my <a href="https://stackoverflow.com/questions/5421892/getselection-not-working-in-ie">other question</a>, which was <a href="https://stackoverflow.com/questions/5421892/getselection-not-working-in-ie#answer-5424222">answered</a> by <a href="https://stackoverflow.com/users/532870/elian-ebbing">Elian Ebbing</a>. I now need to get this working for an iframe (dont ask).</p> <p>It's basically a wisiwig editor that uses an iframe.</p> <p>I've coded up the test environment on <a href="http://jsfiddle.net/HMRMv/" rel="nofollow noreferrer">jsfiddle</a>.</p> <p>Code is as follows:</p> <p><strong>CSS:</strong></p> <pre><code>h1{font-size:150%; border-bottom:1px solid #ddd; margin:20px auto 10px;} </code></pre> <p><strong>HTML:</strong></p> <pre><code>&lt;h1&gt;Normal Text (works)&lt;/h1&gt; &lt;p&gt;Alex Thomas&lt;/p&gt; &lt;button id="click"&gt;Click&lt;/button&gt; &lt;h1&gt;iFrame&lt;/h1&gt; &lt;p&gt;Type in some text:&lt;/p&gt; &lt;iframe id="iframe"&gt;&lt;/iframe&gt; &lt;br /&gt;&lt;button id="iClick"&gt;Click&lt;/button&gt; </code></pre> <p><strong>jQuery</strong></p> <pre><code>(document).ready(function() { setTimeout(makeEdit,10); }); $('#click').click(function(){ var range = document.selection.createRange(); range.pasteHTML("&lt;span style='color: red'&gt;" + range.htmlText + "&lt;/span&gt;"); }); $('#iClick').click(function(){ var range = document.selection.createRange(); range.pasteHTML("&lt;span style='color: red'&gt;" + range.htmlText + "&lt;/span&gt;"); }); function makeEdit(){ document.getElementById("iframe").contentWindow. document.designMode="on"; }; </code></pre> <p>I really hope someone can help me out... Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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