G
Guest
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.PasteHTML 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.IHTMLDocument2 = DirectCast(EditorHTML.Document,
mshtml.IHTMLDocument2)
Dim oSelection As mshtml.IHTMLSelectionObject = Doc.selection
Dim oDocLink As mshtml.HTMLAnchorElementClass
Dim oTxtRange As mshtml.IHTMLTxtRange
If oSelection.type = "Text" Then
oTxtRange = DirectCast(oSelection.createRange(), mshtml.IHTMLTxtRange)
sHTMLText = oTxtRange.htmlText
If InStr(sHTMLText, "<a", CompareMethod.Text) = 0 Then sHTMLText = "<A>" &
sHTMLText & "</A>"
oDocLink = DirectCast(Doc.createElement(sHTMLText),
mshtml.HTMLAnchorElementClass)
oDocLink.innerHTML = oTxtRange.text
...This is where the dialog window pops up and allows the Link to be edited.
oTxtRange.pasteHTML(oDocLink.outerHTML)
End If
Thanks
Jason
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.PasteHTML 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.IHTMLDocument2 = DirectCast(EditorHTML.Document,
mshtml.IHTMLDocument2)
Dim oSelection As mshtml.IHTMLSelectionObject = Doc.selection
Dim oDocLink As mshtml.HTMLAnchorElementClass
Dim oTxtRange As mshtml.IHTMLTxtRange
If oSelection.type = "Text" Then
oTxtRange = DirectCast(oSelection.createRange(), mshtml.IHTMLTxtRange)
sHTMLText = oTxtRange.htmlText
If InStr(sHTMLText, "<a", CompareMethod.Text) = 0 Then sHTMLText = "<A>" &
sHTMLText & "</A>"
oDocLink = DirectCast(Doc.createElement(sHTMLText),
mshtml.HTMLAnchorElementClass)
oDocLink.innerHTML = oTxtRange.text
...This is where the dialog window pops up and allows the Link to be edited.
oTxtRange.pasteHTML(oDocLink.outerHTML)
End If
Thanks
Jason