473,763 Members | 9,275 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MSHTML PasteHTML function duplicating Tag

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

Apr 28 '06 #1
5 3884
Hi Jason,

Thanks for your post!

Can you provide a little sample project to demonstrate the problem? It will
be helpful to the understanding. Also, you'd better post the details steps
to reproduce the problem.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 28 '06 #2
Jeffery,

The editor is part of a larger application I am building...If the following
information does not help you understand my problem I will try to create a
standalone version to reproduce the problem.

I have created an Editor using the WebBrowser component
A section within the document contains the following HTML
<P><A href="http://test.com">testi ng</A></P>
<P> </P>

In the editor I highlight the link (the word testing)

The following code then executes

Dim Doc As mshtml.IHTMLDoc ument2 =
DirectCast(Web. Document.DomDoc ument, mshtml.IHTMLDoc ument2)
Dim oSelection As mshtml.IHTMLSel ectionObject = Doc.Selection
Dim oDocLink As mshtml.HTMLAnch orElementClass = Nothing
Dim oControlRange As mshtml.IHTMLCon trolRange = Nothing
Dim oTxtRange As mshtml.IHTMLTxt Range = Nothing
Dim sHTMLText As String = ""

oTxtRange = DirectCast(oSel ection.createRa nge(), mshtml.IHTMLTxt Range)

'I'm not setting these..I'm showing you the value for each of the
properties. These values are as expected.
'oTextRange.tex t="testing"
'oTextRange.HTM Ltext="<A href="http://test.com">testi ng</A>"

'As you can see from the text below that All I am doing is pasting back
exactly the same HTMLtext I got from the Selection object..
sHTMLText = oTxtRange.htmlT ext
oTxtRange.paste HTML(sHTMLText)
Return

what is returned in the HTML Doc is:
<P><A href="http://test.com">testi ng</A><A href="http://test.com"></A></P>
<P> </P>

as you can see, the link tag is duplicated but with no text between the <A>
and </A>.

Now if I pass just a piece of text to the PasteHTML function like

oTxtRange.paste HTML("New Link")
then I get
<P><A href="http://test.com">New Link</A></P>
<P> </P>

In this case, no duplicate...

My only option at this time is to simple execute
oTxtRange = DirectCast(oSel ection.createRa nge(), mshtml.IHTMLTxt Range)
oTxtRange.execC ommand("CreateL ink", True, Nothing)

instead of using my own code to do the updating. I really don't want to use
this because the default Hyperlink dialog does not allow me to update any
other attributes of the tag like class or style etc...

Is there a bug here in mshtml?? or am I mis-understanding the way pasteHTML
works?
Again if you are unable to understand my problem then I will try and put
together a small app to show you the problem..

Thanks
Jason
""Jeffrey Tan[MSFT]"" wrote:
Hi Jason,

Thanks for your post!

Can you provide a little sample project to demonstrate the problem? It will
be helpful to the understanding. Also, you'd better post the details steps
to reproduce the problem.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

May 4 '06 #3
Hi Jason,

Thanks for your feedback.

No, I can understand your problem in the first reply. But for efficient
purpose, I recommend you create a simple sample project for demonstration.
With reproduce project, it is better for us to do research. Thanks for your
understanding.

You can attach the project as an attachment in the further reply.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

May 4 '06 #4
I think I've found a workaround (or may be that's the way it's supposed to
work)

I am exececuting the "unlink" command right before I paste the HTML. If I
find that it does not work I'll put together a test app for you...

Thanks
Jason


""Jeffrey Tan[MSFT]"" wrote:
Hi Jason,

Thanks for your feedback.

No, I can understand your problem in the first reply. But for efficient
purpose, I recommend you create a simple sample project for demonstration.
With reproduce project, it is better for us to do research. Thanks for your
understanding.

You can attach the project as an attachment in the further reply.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

May 4 '06 #5
Ok, if you have any further problem, please feel free to post. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

May 5 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2772
by: Charles Law | last post by:
Sorry for the cross post, but I'm not sure who is best placed to answer this one. This is the most bizarre behaviour of MSHTML and streams. I have a WebBrowser control that contains nothing but some default HTML. I want to copy the document and modify it before saving it to disk. So, I clone the document like this:
3
2717
by: Simon Wigzell | last post by:
I'm using a 3rd party (htmlarea) WYSIWYG html editting tool. it works great most of the time. I have a problem where I've made my own function to create a bookmark type link. e.g. I want to turn the word "Bottom" into a link to the bottom of the page where resides a bookmark e.g. <a name="Bottom"></a> The 3rd party software in it's guts has this command: sRange.pasteHTML(str1 +sHtml+ str2) Where str1 = <a href="#Bottom">
2
1971
by: colinhumber | last post by:
I'm running this line of code: oTarget.pasteHTML(formattedHtmlText); where oTarget is a text range object. When formattedHtmlText is, say, "<STRONG><BUTTON class=placeHolder>]</BUTTON>&nbsp;text</STRONG>" the HTML is pasted properly and the UI is changed accordingly.
0
1933
by: Giuseppe | last post by:
Hi I've this problem Inside a winform application I've put a "webbrowser" control I've tried to catch the oncontextmenu event of the loaded HTML document with the following approach 1) In the event handler AxWebBrowser1.DocumentComplete I've put: Dim doc As mshtml.HTMLDocument
14
7494
by: Vibhu Bansal | last post by:
Hello, I am having certain problems in trying to use the function createDocumentFromUrl in VB.NET but get this error.."Object reference not set to an instance of object". Here is the code that I am using Imports mshtml Public DocumentFactory As HTMLDocument Public Function GetWebPage(ByVal strURL As String) As HTMLDocument
7
5908
by: Desmond Cassidy | last post by:
Hi, I have being trying to get a grip of HTML data manipulation and am using the mshtml class and System.Net to retriver HTML pages. Now as far as I can see, one can read HTML in different ways. 1. Using the WebBrowser and loading the HTML into the mshtml.HTMLDocument class and then step through the various tags (input, a), tables etc. 2. Use System.Net.WebRequest/Response to load the data into a HTML string using a Stream Reader. Now...
1
2136
by: geevaa | last post by:
Hi All, Try the example javascript given in this link in IE and Firefox. http://www.java2s.com/Code/JavaScript/Node-Operation/pasteHTMLExample.htm <html> <body>
1
8721
by: michelqa | last post by:
Hi, I'm doing a kind of control picker like the one in spy++ but for html document. When the control picker is over an IFRAME, the mshtml function ElementFromPoint return an IFrame element. How can I identify this particular frame/iframe in the frame collection??? I can only select frame in the framecollection by using
16
3724
by: markjavascript | last post by:
Hi, In an editable div, I inserted a big letter, Rng.pasteHTML("<font size=5>A</font>");,fine. However, after that, when type in other letters, (sometimes) I got big letters with size=5. Here is the code: <html> <script> function Test() {
0
9564
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10002
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.