How do you write to the DOM and make it stick? -- VB6 Mshtml Webbrowser control
- From: mtbergan@xxxxxxx
- Date: 15 Dec 2006 18:08:29 -0800
When I insert a node into a loaded web-page, the node insertion gets
totally ignored w/o error. Unless you step through it (F8) or first
display a message box (even if it's compiled it'll work). Otherwise
it's as if it slipped right over the call.
Here's the VB6 (SP6) code that simply attempts to place an image
with/In an existing <TD> element on a webpage. It works in the VB IDE
if you manually step through it; fails if you just run it.
Note:
WebBrowser is the WebBrowser control dropped onto a VB form
m_oDocument is an MSHTML.HTMLDocument
Private Sub ThisShouldWork()
Dim oCell As MSHTML.HTMLTableCell
Dim oImg As MSHTML.HTMLImg
Set m_oDocument = WebBrowser.Document
Set oImg = m_oDocument.createElement("img")
oImg.src = "C:\images\widget.jpg"
Set oCell = WebBrowser.Document.All("TMainData")
If oCell.canHaveChildren Then
oCell.insertAdjacentElement "beforeEnd", oImg
End If
End Sub
This code works fine *IF* you place a breakpoint before the
"...Document.All..." function call, as well as the
"...insertAdjacentElement ..." function call. Or, if you throw up a
message box prior to calling either one of these (compiled or not).
Otherwise, they return "Nothing" with no error, and the webpage's new
HTML
is not updated. I've tried many variations of the code above, such as
not using the oCell variable, using the Document object to get the
element, etc.
I have ensured that the Document has been fully loaded. I've tried
using DoEvents before it as well as putting in a 30 second loop before
it, with no success.
Why? Nobody else having this problem?
.
- Prev by Date: Re: System.UnauthorizedAccessException : Access is denied when calling click on an anchor object
- Next by Date: Pluggable Namespace Handler Problem
- Previous by thread: Tabbing
- Next by thread: Pluggable Namespace Handler Problem
- Index(es):