Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Insert HTML into Browser control w/o actual HTML file 2

Status
Not open for further replies.

Karl Blessing

Programmer
Feb 25, 2000
2,936
0
0
US
I have a browser control (microsoft internet controls) I would like to figure out how I Can just throw HTML codes into it for testing viewing etc, withing actually have an html file on disk, nor having it goto a url. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
What-ho,

try this:

put the HTML you want to display into a string variable and then pass it to the Browser Control like this:

BrwMain.Document.body.innerHTML = HTMLSource

Where BrwMain would be your Browser control and HTMLSource your string containing the HTML you want to display.


Give it a go...



Cheerio,

Paul
[sig][/sig]
 
I tried Document, but when i do . aftet document nothing shows, when I try to run with that full thing you have, I get this error:
&quot;Run-Time Error '91':
Object variable or With block variable not set&quot;

the code is:

[tt]
Private Sub Form_Load()
WebBrowser1.Document.body.innerHTML = &quot;<HTML><BODY><H1>Hi</H1></BODY></HTML>&quot;
End Sub

[/tt] [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Hiya,

OK, sorry about that, I'm just going through some code I'm working on that happens to have a WebBrowser control in it...

Warning - Guess Occurring

The reason that the properties of the Document property of the WebBrowser control aren't available at design time are because they apply to a document which must be loaded into the WebBrowser control itself, which can only happen at runtime.

This implies that these properties will only work if there is a document loaded, as they apply to it, so to use them, the first thing you must do is load a document into the WebBrowser control.

So, in your form load, before you do anything else, add the following line:

WebBrowser1.GoHome

Then your code will work.

Now, as to where the Home is actually set, I'm not sure, but I think it might be your default homepage as set through Internet Explorer.


Anyway, whatever the reason, this'll fix the Object variable not set, blah blah blah error :)


Hope this helps...


Cheers then,

Paul
[sig][/sig]
 
no that doesnt fix it, (unless you make sure that GoHome is completely finished) but using your exact same concept, i used this on form load

[tt]
WebBrowser1.Navigate &quot;About:blank&quot;
[/tt]

this way
1) I dont need to download or connect to anything
2) It's blank

Thanks for you help. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Why dont you write it to a file then display the file and when the program unloads kill the HTML that you created. That is the simpleset way that I can think of. [sig][/sig]
 
well it's not that simple if you think about it, it would be slow , and you would need to work with many extra controls, and would kind of defeat the idea of an HTML &quot;Preview&quot; from what he did above, now all I gota do is set that innerHTML to whatever I want, it's a single line, and doesnt need any file creation at all. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
no that doesnt work, it'll generate the same error highlighing the .Open line, I think my method of navigating to &quot;About:Blank&quot; then filling it is good enough, and it works. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
The deal is like NFI said (Seems to play to .Open as well) is that the broswer window must have some actual content in it in order for anything to be inserted, almost like trying to insert a value into a NULL/Nothing variable. Naturally I dont want anything shown prior to dynamically throwing something in so &quot;About:Blank&quot; is the best choice, the browser window (Shcdwl.dll however it's spelled) &quot;IS&quot; Internet Explorer (if you watch the code sometimes, you'll notice IE is nothing more than a navigational wrapper and IDE wraped around the DLL View Window. and is in fact an ActiveX control itself.)

so I myself consider my problem solved, or least workable at the time being.

Thanks for your sugestion tho, I'll certainly remeber it. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
Karl,
The code I posted works on my system without errors. I never post untested code. Don't know why it fails for you. As I remember, you're using IE 5.5, so we should have the same version of the WebBrowser control. What references do you have in your project? [sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
References : VBA, VB Runtime, VB Object and Procedure, OLE Automation, Microsoft Internet Controls

Components : Microsoft common Dialog control 6.0, Microsoft Internet Control
[sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
I think I've figured out why my code works and yours doesn't. I used the VB application wizard to create my project, and the wizard sets a default start page for the control. It seems that once the project has been saved, the browser control somehow remembers this page, and attempts to load it.

So your guess about not having a document is probably right. [sig]<p>nick bulka<br><a href=mailto: > </a><br><a href= </a><br>Get your technical books at Bulka's Books<br>
[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top