raheelasadkhan
asked on
Using MSHTML to modify HTML Elements
Hello,
My application composes an HTML page at run time using content pulled from the net. Once composed, it is saved to file and displayed in aWeb Browser control.
Once displayed I need to add the (TARGET="_blank") atribute to all anchor tags. I am using MSHTML as follows:
private void wbUserRSS_NavigateComplete 2(object sender, AxSHDocVw.DWebBrowserEvent s2_Navigat eComplete2 Event e)
{
// Force all links in the document to open external windows
mshtml.HTMLDocument htmlDocument;
htmlDocument = (mshtml.HTMLDocument) this.wbUserRSS.Document;
// How to access all the <A> elements in the document?
}
Also, are there any good articles out there explaining possibilities with MSHTML in an easy way (unlike the MSDN documentation)?
Thanks,
Khan
My application composes an HTML page at run time using content pulled from the net. Once composed, it is saved to file and displayed in aWeb Browser control.
Once displayed I need to add the (TARGET="_blank") atribute to all anchor tags. I am using MSHTML as follows:
private void wbUserRSS_NavigateComplete
{
// Force all links in the document to open external windows
mshtml.HTMLDocument htmlDocument;
htmlDocument = (mshtml.HTMLDocument) this.wbUserRSS.Document;
// How to access all the <A> elements in the document?
}
Also, are there any good articles out there explaining possibilities with MSHTML in an easy way (unlike the MSDN documentation)?
Thanks,
Khan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes that looks about right. I'll give it a try and get back to you. Thanks.
ASKER
I added the following line to the processing section:
((mshtml.HTMLAnchorElement ) node).target = "_blank";
This seems to have no effect. The links that were opening in the same window before are stilldoing the same.
((mshtml.HTMLAnchorElement
This seems to have no effect. The links that were opening in the same window before are stilldoing the same.
ASKER
My bad. My example can update the attribute value but does nothing if the attribute is not present. This works:
((mshtml.HTMLAnchorElement ) node).setAttribute("TARGET ", "_blank", 0);
Thanks again.
On another note, is there a good documentation source or article around with "How to's"? The MSDN documentation is very unfriendly for MSHTML.
((mshtml.HTMLAnchorElement
Thanks again.
On another note, is there a good documentation source or article around with "How to's"? The MSDN documentation is very unfriendly for MSHTML.
you should take a look after the page is loaded in the source of the page, i dont think that you had changed the correct tags, because the page is finished with loading and remains in memory.
ASKER
On your last comment, if you alter HTML at runtime via the DOM like we are doing, the changes DO NOT show up in 'View Source'. At least that was my observation.
oh ok, great that it works. i dont know about any documentations for that component. i had done that example only with debugging and looking at the webbrowsers fields.
maybe you could take a look in the msdn for net2, because microsoft integrated now a webbrowser component, which is a managed wrapper for the component, you used. maybe you can find more information there.
ASKER
Yeh, the switch to 2.0 is inevitable. Thanks again.
ASKER