Jump to content

onclick from div not working in IE (with execCommand)


fivestringsurf

Recommended Posts

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.