Hello,
I wrote a little rich text editor. Like many widgets of this type, it uses an iframe that contains a div element with contentEditable set to true. It works pretty well except for one thing: I would like users to be able to select an image and then click a button to edit the image's HTML attributes. I've waded through pages and pages of Google results but have not found a solution that works in W3C compliant browsers (although I did find some results that explain how to do this in Internet Explorer). I am able to get a text selection without any problem; but the same methods that work for text do not work for an image. I have tried the following:
As you can see I was kind of reaching by the end there. I'm all out of ideas now, so if anybody has tips or pointers I would be glad to hear them.
Thanks very much!
I wrote a little rich text editor. Like many widgets of this type, it uses an iframe that contains a div element with contentEditable set to true. It works pretty well except for one thing: I would like users to be able to select an image and then click a button to edit the image's HTML attributes. I've waded through pages and pages of Google results but have not found a solution that works in W3C compliant browsers (although I did find some results that explain how to do this in Internet Explorer). I am able to get a text selection without any problem; but the same methods that work for text do not work for an image. I have tried the following:
Code:
iframe.contentWindow.getSelection();// returns an empty string. iframe.contentWindow.getSelection().getRangeAt(0);// also returns an empty string iframe.contentWindow.getRangeAt(0);// is not a function. document.activeElement;// returns the object HTMLButtonElement iframe.contentDocument.activeElement;// returns the object HTMLDivElement - the image's parent node. iframe.contentWindow.activeElement;// is undefined. iframe.contentDocument.selection;// is undefined. iframe.contentWindow.selection;// is undefined.
Thanks very much!
Comment