Clearing WebBrowser contents

J

jhattersley

Hi Folks,

Wonder if you can help...

All I'm trying to do is load a couple of simple HTML pages (in memory)
into the WebBrowser control, one after the other. I don't seem to be
able to clear the contents of the WebBrowser before I show the next
page, they're appended one after the other.

I've got some really simple code:

private void Form1_Load(object sender, System.EventArgs e)
{
Object o = null;
axWebBrowser1.Navigate("about:blank", ref o, ref o, ref o, ref o);
document = (IHTMLDocument2) axWebBrowser1.Document;
document.writeln("<h1>One</h2>");
}

private void button2_Click(object sender, System.EventArgs e)
{
document = (IHTMLDocument2) axWebBrowser1.Document;
document.clear();
axWebBrowser1.Refresh();
document.writeln("<h1>Two</h1>");
}

Any suggestions, I'm being stupid, but I can't see why and I've spent
too long on this already.

Thanks Dudes.

John
 
F

Fergus Cooney

Hi JH,

This is a guess.

Try navigating to About:blank again in button2_Click..

Regards,
Fergus
 
J

jhattersley

Fergus Cooney said:
Hi JH,

This is a guess.

Try navigating to About:blank again in button2_Click..

Regards,
Fergus

Thanks Fergus, I tried that before. Just for reference the answer to
this one is "RTFM". :) The documentation states that this method isn't
implemented for IHTMLDocument2, and I should've used:

document.write("");
document.close();

Works fine.

Thanks again,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top