fivestringsurf Posted May 21, 2010 Share Posted May 21, 2010 I'm working on some rich text editing techniques to be applied in a larger project. The following code works great in firefox and ok in ie when i am triggering the onclick from a <button> but not a <div> this makes little sensse to be...especially because if i stick an alert(); function into the js (doRichEditCommand() function) it outputs to the browser ...but the execCommand doesn't...at least not by cllicking the <div>. Note: clicking a <button> to trigger the event does work in ie? <script type="text/javascript"> function Init() { getIFrameDocument("editorWindow").designMode = "On"; } function getIFrameDocument(aID){ // if contentDocument exists, W3C compliant (Mozilla) if (document.getElementById(aID).contentDocument){ return document.getElementById(aID).contentDocument; } else {// IE return document.frames[aID].document; } } function doRichEditCommand(aName, aArg){ if (window.getSelection) { //ff getIFrameDocument('editorWindow').execCommand(aName,false, aArg); document.getElementById('editorWindow').contentWindow.focus() } else if (document.selection) { // ie //alert('broken'); editorWindow.document.execCommand(aName,false, aArg); } } </script> </head> <body onload="Init()"> <br /> <div onclick="doRichEditCommand('foreColor','ff0000')" style="border:1px solid Red;width:30px;">Red</div> <button onclick="doRichEditCommand('foreColor','0000ff');" style="font-weight:bold;">Blue</button> <br /> <iframe id="editorWindow" width="400" height="40" ></iframe> Link to comment https://forums.phpfreaks.com/topic/202534-onclick-from-div-not-working-in-ie-with-execcommand/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.