cancan101

I am trying to wrap the users selection (or a IHTMLTxtRange) with font or span tags that have a given class.

The best that I can do now is: pRangeToRender.execCommand("BackColor", false, SOMECOLOR)

I then use IHTMLElementCollection allEls = doc.getElementsByTagName("FONT"); and check each tag if it's SOMECOLOR. If it is, I clear the color and set the font tag's class. This is quite slow on large selection.

Is there some better way to do it


Re: Internet Explorer Extension Development Wrap selection or IHTMLTxtRange in Font or Span tags of a given class

Artie Sluka

This is kind of a shot in the dark as I have never tried this, but perhaps you could retrieve the block of text using pRangeToRender.htmlText. You could then wrap that with a SPAN tag, and then try to re-insert it by setting the pRangeToRender.text property. This may or may not work depending on how the differences between the read-only property "htmlText" and the read/write property "text" are implemented.

If you can write HTML to the "text" property and have it render correctly, that might work for you.





Re: Internet Explorer Extension Development Wrap selection or IHTMLTxtRange in Font or Span tags of a given class

cancan101

The solution suggested does not work for large selections as span (or font tags) cannnot span certain element tpyes. The good thing about using IE's execcommand is that it wraps the selection with the proper SPAN (or Font) tags in the proper places.