-
July 27th, 2006, 01:11 PM
#1
Set WebBrowser.DocumentText doesn't do anything
Hello!
I just started with .net. I made a new C++-CLR-Windows-Forms-Applicationin VS 2005, which has one simple form by default. I added a WebBrowser-Control to it.
Now I just want to set the html-code inside the WebBrowser-Control. I found the DocumentText-Property and set it:
Code:
Form1(void)
{
InitializeComponent();
//
this->webBrowser1->DocumentText = L"<html><body>It works!</body></html>";
//
}
Ok, the program runs, but it shows nothing inside webBrowser1. I had a look at the sourcecode via the popup-menu of the WebBrowser, it just says "<HTML></HTML>".
What am I doing wrong?
-
August 8th, 2006, 07:11 PM
#2
Re: Set WebBrowser.DocumentText doesn't do anything
it's not for html, and youll probably find the browser is reluctant to do anyhting before you navigate()
its a pain in the abackside, but i've actually found the easiest way to get a web browser to show something is to write that something to disk and then Navigate2() the file you wrote.. it sounds lame, but it'll save you a lot of hair pulling!
-
August 9th, 2006, 12:05 AM
#3
Re: Set WebBrowser.DocumentText doesn't do anything
Originally Posted by cjard
it's not for html, and youll probably find the browser is reluctant to do anyhting before you navigate()
its a pain in the abackside, but i've actually found the easiest way to get a web browser to show something is to write that something to disk and then Navigate2() the file you wrote.. it sounds lame, but it'll save you a lot of hair pulling!
Much more elegant and effective way of populating web browser control with html is to use Write method of Document object of WebBrowser control.
-
March 23rd, 2007, 04:47 PM
#4
Re: Set WebBrowser.DocumentText doesn't do anything
Originally Posted by Igor Soukhov
Much more elegant and effective way of populating web browser control with html is to use Write method of Document object of WebBrowser control.
When the WebBrowser control is first made, the Document object is null. So, how do you get to the point where you can invoke Document.Write() ?
Zytan
-
March 23rd, 2007, 04:57 PM
#5
Re: Set WebBrowser.DocumentText doesn't do anything
Simply, you just navigate to .......... about:blank
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
March 23rd, 2007, 04:59 PM
#6
Re: Set WebBrowser.DocumentText doesn't do anything
Ok, I was thinking that. So, that implies it has not navigated ANYWHERE, not even about:blank, before you tell it to do so.
Thanks!
Zytan
-
January 23rd, 2008, 04:32 PM
#7
Re: Set WebBrowser.DocumentText doesn't do anything
I try this setting DocumentText and Document.Write and it works fine on the first try but when I try to change the display to another page, it doesn't work. Whatever I displayed first remains forever.
If I navigate to blank then it will go blank but Document.Write basically no longer works.
I tried Invalidate too.
It's really funny to me how I can set a property and then read it and it contains the value it had before I set it. If it's a readonly property then don't let me set it! Throw an exception or give me a compile error!
-
January 23rd, 2008, 04:53 PM
#8
Re: Set WebBrowser.DocumentText doesn't do anything
Try using Document.OpenNew before calling Document.Write.
I would still have expected an exception.
-
February 29th, 2008, 11:24 AM
#9
Re: Set WebBrowser.DocumentText doesn't do anything
What the OP is doing with his code will work fine provided a couple things:
* Don't set DocumentText in the constructor. Use Form_Load or your own method.
If you set DocumentText in the constructor, you will not be able to set it again anywhere in the application. Be sure to check that the Form Designer hasn't set it either.
* You can only set DocumentText once per method call. This is odd and most likely a bug, but it's true.
For example: setting DocumentText in a for-loop will only set properly on the first iteration of the loop.
You can however, create a small method to set DocumentText to the passed in string, then call this method in a for-loop.
-C6
-
April 1st, 2011, 03:05 PM
#10
Re: Set WebBrowser.DocumentText doesn't do anything
I like to use the WB to play youtube vids, because Flash drives me crazy. The WB just needs a little push, like application.doevents. I haven't needed to naviate to about:blank or anything else to make this work.
Dim DocText as string= "Your Text"
WebBrowser1.DocumentText = DocText
Application.DoEvents
(Without DoEvents, it won't que the next video, and either it goes blank, or plays the old video again)
-
May 4th, 2011, 01:59 AM
#11
Re: Set WebBrowser.DocumentText doesn't do anything
This works fine for me:
string html = textBox1.Text;
html = html.Replace("\r\n", "<br />");
webBrowser.Navigate("about:blank");
webBrowser.Document.OpenNew(false);
webBrowser.Document.Write(html);
webBrowser.Refresh();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|