jmace Posted January 31, 2011 Share Posted January 31, 2011 Does anyone know anything about selecting text in an editable iframe? The following code kind of works in FireFox (it's a little buggy), but doesn't work at all in anything else. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>ADVANCED EDITOR TEST PAGE</title> <script type="text/javascript"> function framego(){ document.getElementById("frame").contentDocument.designMode = "On"; document.getElementById("frame").contentWindow.document.body.innerHTML = "TEST [here] ING"; } function selectArea(){ o=document.getElementById('frame'); if(o.contentWindow.getSelection) sel = o.contentWindow.getSelection(); //FF else sel = o.contentDocument.selection.createRange(); //IE range2=sel.getRangeAt(0); var range = document.createRange(); range.setStart(sel.anchorNode,5); range.setEnd(sel.anchorNode,11); //remove the old range and add the newly created range sel.removeRange(range2); sel.addRange(range); o.focus(); } </script> </head> <body onload="framego()"> <iframe id="frame"></iframe> <button onclick="selectArea()">TEST</button> </body> </html> It's supposed to select the word "Here" in the iframe. A million thanks to anyone who can point me in the right direction on this one. :-) Quote Link to comment https://forums.phpfreaks.com/topic/226208-selecting-text-in-an-iframe/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.