Loading HTML into a WEB Browser Control from Variable

This is sample code. Add error handling and adjust to your requirements as necessary.

lcHtml = [<html><body>Hello World!</body></html>]
lnLoadTimeout = 3       && seconds
WITH Thisform.oWeb.OBJECT
	* Wait for load completion
	lnStartSeconds = SECONDS()
	DO WHILE .ReadyState <> 4 ;
			AND (SECONDS()-lnStartSeconds <= lnLoadTimeout )
	* Load HTML into Web Browser Control
	* Wait for load completion
	lnStartSeconds = SECONDS()
	DO WHILE .ReadyState <> 4 ;
			AND (SECONDS()-lnStartSeconds <= lnLoadTimeout )

See Also Loading XML into a WEB Browser Control from Variable

Web Browser Code Sample

Thanks Sergey

Thanks !

Thanks Sergey,

This was extremely helpful. I just found myself in a situation when the WebBrowser could not finish loading a simple HTML file. (On the background I have another ActiveX component running that was probably bringing the issue). Using this aproach everything runs perfectly.
Thanks again!

Just for the records, in case this may help someone else.
My final solution was to use SYS(2333,1), to acrtvate the ActiveX dual interface support.



Switching pages...

Sergey, the above code works perfectly. I was searching for a solution for a long time. i modifed the code to have the lcHtml be a filetostr( "c:\temp\test.html") and test.html changes as i need it to. I have a question though. When I go to load a new HTML file the code stops at the  .Navigate("about:blank") . I implemented the sys( 2333,1) but that did not seem to help. I have to C-A-D/Task Manager to terminate foxpro. Any help would be appreciated.

Thanks, Josh.

Re: Switching pages...

Hi Josh,

Can you load HTML and than "about:blank" in IE w/o problem?

BTW, you can load HTML from a file directly

lcHtmlFileName = "c:\temp\test.html"
.Navigate2("file://" + lcHtmlFileName)

Switching pages...

Why is it necessary to always navigate to a the "about:blank" page before loading the actual page that I want to show?

Re: Switching pages...

It's not necessary. I prefer to do it this way.

I'm finding that if I *do

I'm finding that if I *do not* call the blank page, the browser control does not refresh to the new page at all.

I guess you also remove code

I guess you also remove code that waits for load to complete. Anyway, The Web Browser control works much better when loading HTML from a file.


Hi Sergey.
I have problem with this Active X, send a Ole error code
and then when I run the example in this line: .Document.Open()
occurr other error. I think that the second error is a consequence of the first error.
You have any idea about that ....


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <java>, <powershell>, <tsql>, <visualfoxpro>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.