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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.