Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IHTMLDocument2

Posted on 2003-11-01
9
Medium Priority
?
1,359 Views
Last Modified: 2013-12-03
Hi

I have written an IE BHO that uses the IHTMLDocument2 interface to alter the HTML, i need to be able to get the complete modified source including all the tags <!DOCTYPE....<HTML>....</HTML>. the get_body->get_innerHTML only gives me the <BODY>.....</BODY> section, thats no good i need the lot.

I either need to have it as a sting (BSTR) or be able to save it to a file.

i have already seen the few questions on here that suggest get_body, please dont suggest them... it dont work how i want it to.

Ta

Paul
0
Comment
Question by:makerp
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 6

Expert Comment

by:purpleblob
ID: 9663158
I've done this in C# but using IHTMLDocument3 object - however the following C++ should work

QI your IHTMLDocument2 to get an IHTMLDocument3 interface (hopefully) you'll get an IHTMLDocument3 interface back and from this you should be able to get what you want.

Here's the source (note: it's in the most basic form, i.e. no ATL etc. and for brevity all error handling has been removed).

IHTMLDocument3 pHTMLDoc3;
pHTMLDoc2->QueryInterface(IID_IHTMLDocument3, reinterpret_cast<void**>(&pHTMLDoc3);

IHTMLElement* pDocElem;
pHTMLDoc3->get_DocumentElement(&pDocElem);

pHTMLDoc3->Release();

BSTR bstrHTML;
pDocElem->get_OuterHTML(&bstrHTML);
pDocElem->Release();

I've not tested this C++ code but converted it to C# (as I've been using the browser recently in C#) and it seems to produce everything <html> to </html>.

0
 
LVL 8

Expert Comment

by:_corey_
ID: 9663996
I'm pretty sure that'll work for IHTMLDocument2 ?
0
 
LVL 6

Assisted Solution

by:purpleblob
purpleblob earned 1000 total points
ID: 9664252
IHTMLDocument2 doesn't include the get_DocumentElement method. However there's another interface called HTMLDocument which also supports this method and can be used in place of IHTMLDocument3.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 2

Accepted Solution

by:
gimmeadrink earned 1000 total points
ID: 9709384
What about this...

HRESULT IHTMLDocument2::get_all(IHTMLElementCollection **p);

Its a zero based collection of all the elements in a webpage.
(see http://msdn.microsoft.com/workshop/author/dhtml/reference/collections/all.asp for more info)


the other option is 'tostring'  (http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/document2/tostring.asp)

I have used both of these (although a while ago) in visual basic, should act the same way for VC++ or whatever you are using.

HTH

0
 
LVL 8

Expert Comment

by:_corey_
ID: 9716457
ToString actually does that?  I voiced a thought about that in an earlier question but never actually tried it.
0
 
LVL 2

Expert Comment

by:gimmeadrink
ID: 9719327
hmmm, i might double-check..... it was a while ago that i used it ;)

I'll get back to ya.
0
 
LVL 10

Author Comment

by:makerp
ID: 9733611
i have solved this by getting the IPersistFile interface from the IHTMLDocument2 object...

thanx anyway
0
 
LVL 10

Author Comment

by:makerp
ID: 10800469
sorry about the delay - since the update of the look & feel of EE the flash, adverts and animated gifs anoy slightly.

none of the solutions proposed here are really suitable because of the way IE alters the raw HTML in its object model. anyway i will split the points.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question