Hi,
I'm developing an HTML Editor Control using VB.Net 2003 for an application
that used to use the DHTML Editor Control that is no longer supported. Well,
it's been fun but I've hit a wall with an intermittent problem working with
editing Hyperlinks.
As you can see the following HTML code contains two links each in a
paragraph tag.
In the Editor, when I highlight the first link and execute code to select,
turn into a TxtRange object, update the tag href and then use the
txtRange.PasteH TML function the output duplicates the link. (see second html)
<HTML><HEAD>
<META content="MSHTML 6.00.2900.2873" name=GENERATOR> </HEAD>
<BODY>
<P><A title=Tip href="http://test.com/">Test</A></P>
<P><A title=tip2 href="http://test2.com/">Test2</A></P></BODY></HTML>
HTML showing duplicate
<HTML><HEAD>
<META content="MSHTML 6.00.2900.2873" name=GENERATOR> </HEAD>
<BODY>
<P><A title=Tip href="http://test.com/">Test</A><A title=Tip
href="http://test.com/"></A></P>
<P><A title=tip2 href="http://test2.com/">Test2</A></P></BODY></HTML>
As you can see above the link got duplicated.. This problem only appears to
happen when the anchor tag resides inside a paragraph tag with no space
between the </a> and </p>. Is there a bug in the MSHTML dll or am I missing
something in the code??
Here is the Code or rather a snippet of the part that's important to the
problem
Dim Doc As mshtml.IHTMLDoc ument2 = DirectCast(Edit orHTML.Document ,
mshtml.IHTMLDoc ument2)
Dim oSelection As mshtml.IHTMLSel ectionObject = Doc.selection
Dim oDocLink As mshtml.HTMLAnch orElementClass
Dim oTxtRange As mshtml.IHTMLTxt Range
If oSelection.type = "Text" Then
oTxtRange = DirectCast(oSel ection.createRa nge(), mshtml.IHTMLTxt Range)
sHTMLText = oTxtRange.htmlT ext
If InStr(sHTMLText , "<a", CompareMethod.T ext) = 0 Then sHTMLText = "<A>" &
sHTMLText & "</A>"
oDocLink = DirectCast(Doc. createElement(s HTMLText),
mshtml.HTMLAnch orElementClass)
oDocLink.innerH TML = oTxtRange.text
...This is where the dialog window pops up and allows the Link to be edited.
oTxtRange.paste HTML(oDocLink.o uterHTML)
End If
Thanks
Jason