简体   繁体   中英

Iframe tag not loaded in Web browser control of Windows form

I have developed a windows form application in which I have added a Web Browser control. In that web browser control I am adding html content like below

<iframe src="pageURL.aspx?ref=iframe" allowtransparency="true" height="310px" width="300px" border="0px" frameBorder="0" scrolling="no" style="overflow-x:hidden;"/>

To assign above content ot web browser I am using following code

wbflyout.Navigate("about:blank");
wbflyout.DocumentText = string.Empty;
wbflyout.Document.OpenNew(true);
wbflyout.Document.Write(dynamic HTML Content);
wbflyout.Refresh();

I tried assigning this content to Web browsers body as below-

wbflyout.Document.Body.InnerHtml = (dynamic HTML Content);

when the form loads a blank white screen is shown.

Why is this happening? If I load only simple heading or text dynamically it works prefect.

I'll try answering both refreshing and manipulating, since I think that's the info you're after.

Refreshing : For refreshing, try using the DocumentText property on the WebBrowser control.

This property is used best when you want to manipulate the contents of an HTML page displayed in the WebBrowser control using string processing tools. You can use this property, for example, to load pages from a database or to analyze pages using regular expressions. When you set this property, the WebBrowser control automatically navigates to the about:blank URL before loading the specified text. This means that the Navigating, Navigated, and DocumentCompleted events occur when you set this property, and the value of the Url property is no longer meaningful. (Source, MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.documenttext(v=vs.110).aspx )

eg:

webBrowser.DocumentText = "<html></html>";

where "<html></html>" is your dynamic html, or for example your iframe.

Manipulating HTML : Next, if you would want to manipulate the HTML itself and refresh it, then I'd advise you to use an HTML specific library to aid you with manipulating HTML. An example of this is HTML Agility Pack : http://htmlagilitypack.codeplex.com/ - also available on NuGet (NuGet AgilityPack Url: https://www.nuget.org/packages/HtmlAgilityPack ). Then after manipulating it you can use that DocumentText property again to load/refresh the HTML.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM