Share WebBrowser Display HTML Content 3-point details tips to resolve the blank after refresh

Source: Internet
Author: User
Tags blank page

Displaying HTML content directly, unlike direct navigation URLs, is easy to handle:

Questions: according to the Microsoft Control property hint, you can use the Webbrowser.documenttext property to assign a value, but this assignment is only valid for the first time, the subsequent switchover does not work.

Here are two tips for your quest:

1: Output HTML content display via WebBrowser.Document.Write (HTML) method.

Because the WebBrowser need to go through a few events before the display, the direct output is not, for this, a bit of skill to use:

Wbshowblog.navigate ("About:blank"); while (wbshowblog.readystate! = webbrowserreadystate.complete) {     

  

Use this method to navigate to a blank page and then output the HTML content that needs to be displayed.

2: Two times display content, should replace with node instead of re-output content

From the beginning, the output is called, and when the content is toggled, there is an occasional problem of not displaying new content after switching.

In many repeated trials, back and forth, when good and bad, decided to deal with the idea of the problem, for this, I think of another way to solve:

if (wbshowblog.document = = null) {String html = Htmltemplate.replace ("{0}", Blogtext); Wbshowblog.navigate ("About:blank "); while (wbshowblog.readystate! = webbrowserreadystate.complete) {    application.doevents ();   }   WbShowBlog.Document.Write (HTML);//There is a problem here, deal with it tomorrow. }else{       wbShowBlog.Document.GetElementById ("Weibospiritbody"). InnerHtml = Blogtext;}

  

The second time, by directly switching the internal node of the innerHTML to display content, rather than re-assigning the browser, this way, the perfect solution to the problem.

3:document.write (HTML) when an IFRAME is present, resolves a mysterious problem that the IFRAME does not display by default

Finally, until one day, the new strategy changes, the content of the ads below, not directly display the content, and want to set an IFRAME to display the Web address, this time found a new problem:

Through the document.write out of the IFRAME unexpectedly show, toss after, found refreshing a browser can show out, for this, and fill up a trick, into:

if (wbshowblog.document = = null)   {   string html = Htmltemplate.replace ("{0}", Blogtext);   Wbshowblog.navigate ("About:blank");   while (wbshowblog.readystate! = webbrowserreadystate.complete)   {      application.doevents ();   }    WbShowBlog.Document.Write (HTML);//There is a problem here, deal with it tomorrow.    Wbshowblog.refresh ();//Do not refresh, IFRAME display does not come out. }else{    wbShowBlog.Document.GetElementById ("Weibospiritbody"). InnerHtml = Blogtext;}

  

is a multi-line refresh, solve the problem, the above is 3 details point.

Share from: http://www.cnblogs.com/cyq1162/archive/2012/03/27/2419655.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.