javascript - getSelection() not working for in IE -


Leading from me, which was done by. Now I need to do this work for an iframe (do not ask).

This is basically an intelligent editor that uses an iframe.

I have coded the testing environment. / P>

The code is as follows:

CSS:

  h1 {font-size: 150%; Border bottom: 1px solid #ddd; Margin: 20px Auto 10px;}   

HTML:

  & lt; H1 & gt; General text (work) & lt; / H1> & Lt; P & gt; Alex Thomas & lt; / P & gt; & Lt; Button ID = "click" & gt; Click & lt; / Button & gt; & Lt; H1 & gt; IFrame & lt; / H1> & Lt; P & gt; Write 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;   

jQuery

  (document) .ready (function () {setTimeout (makeEdit, 10);}); Click $ ('#click') (function () {var range = document.selection.createRange (); Category.petHTML ("& lt; span style = 'color: red' & gt;" + range.htmlText + "& Lt; / span & gt;");}); Click $ ('# IClick') (function () {var range = document.selection.createRange (); Category. Paste HTML ("& lt; span style = 'color: red' & gt;" + range.htmlText + "& Lt; / span & gt;");}); Function Make Edit () {document.getElementById ("iframe"). ContentWindow document.designMode = "on"; };   

I hope someone can help me ... thanks

You need to use the iframe document object to create textRanges:

  function makeframeSelectionRed () {var range = document.getElementById ("Iframe") .contentWindow.document.selection.createRange (); Category. Paste HTML ("& lt; span style = 'color: red'>" + range.htmlText + ""); } $ ('#click'). Click (makeIframeSelectionRed); . Click on $ ('# IClick') (makeIframeSelectionRed);    

Comments