Re: IHTMLDocument2 problem
- From: "jiangsheng[MVP]" <sheng_jiang@xxxxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Sep 2006 22:41:56 -0500
Yes, SetHTML is not working. A walkaround is to create the elements
(IHTMLDocument2::create...) and add them to the documents. If you are create
script elemnts, you need to set the defer attribute to true as well.
--
Regards
Sheng Jiang
Microsoft Most Valuable Professional in Visual C++
http://www.jiangsheng.net
http://blog.joycode.com/jiangsheng/
"RushManbert" <RushManbert@xxxxxxxxxxxxxxxxxxxxxxxxx> дÈëÓʼþ
news:D68F6595-06F4-41B8-B0C4-F535D1650787@xxxxxxxxxxxxxxxx
My app uses MFC and specifically the CHtmlCtrl class developed by Paulis
DiLascia, which is derived from the CHtmlView class provided with MFC.
Essentially, I have a browser control in a modeless dialog. My intention
to render my own XHTML source (don't ask why :-), then load the resultingconfident
HTML string into the control. The class very kindly provides a SetHTML
method. It works and I can load my HTML code and it displays just as
expected. (I have already developed this app for the Mac, so I am
that my rendering code works.)link.
The source for SetHTML is shown below:
//////////////////
// Set document contents from string
//
HRESULT CHtmlCtrl::SetHTML(LPCTSTR strHTML)
{
HRESULT hr;
// Get document object
SPIHTMLDocument2 doc = GetHtmlDocument();
ASSERT (doc);
// Create string as one-element BSTR safe array for IHTMLDocument2::write.
CComSafeArray<VARIANT> sar;
sar.Create(1,0);
sar[0] = CComBSTR(strHTML);
// open doc and write
LPDISPATCH lpdRet;
HRCHECK(doc->open(CComBSTR("text/html"),
CComVariant(CComBSTR("_self")),
CComVariant(CComBSTR("")),
CComVariant((bool)1),
&lpdRet));
HRCHECK(doc->write(sar)); // write contents to doc
HRCHECK(doc->close()); // close
lpdRet->Release(); // release IDispatch returned
return S_OK;
}
As you can see, he gets the underlying IHTMLDocument2 interface, then uses
the Open, Write, and Close methods to replace the HTML.
The problem that I am seeing is when I load a HTML string that contains
links of the form:
<a href="file://localhost/C:/path/to/file.html>Click this</a>
The display shows the links correctly, but if I click on them nothing
happens. The CHtmlCtrl has the OnBeforeNavigate2 event callback, but it
doesn't get called, and the browser doesn't load the page named in the
(Yes it's a valid path, etc.)containing
I created a MFC app based on CHtmlView and made it load the file
the links (which I generated by getting the source from the web browserSetHTML.
control after I loaded the HTML string, so I know that it's the same HTML
source). In that case if I click on a link, the OnBeforeNavigate2 event
callback did get called.
I then went back to my app and changed the loading code to write the HTML
string into a temporary file, then load the temporary file using the
Navigate2 method, rather than directly loading the HTML string with
When I do this, then click on the links, the OnBeforeNavigate2 eventcallback
IS called.SetHTML
This leads me to the conclusion that either there is some bug in the
implementation that causes clicked links to be ignored, or there is a bugout
down in the COM (ActiveX?) control that achieves the same (non)result.
I'm hoping that someone who knows about this stuff can shed some light on
this. For various reasons, I really don't want to write my rendered XHTML
to a disk file and load it (which would be the blunt workaround). I justwant
to keep it in memory.
Anybody have any ideas?
Thanks,
Rush
.
- References:
- IHTMLDocument2 problem
- From: RushManbert
- IHTMLDocument2 problem
- Prev by Date: Re:Custom print preview and GetOptionKeyPath/GetOverrideKeyPath
- Next by Date: Re: Obtaining shortcut from clipboard
- Previous by thread: IHTMLDocument2 problem
- Next by thread: Multiple COccManagers and delete
- Index(es):
Relevant Pages
|