Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

How can I send some HTML code to TWebBrowser control?

Hello,

I have a TWebBrowser control on my form and I want to send some HTML code to it.

How can I do that?

Thanks.
0
AngryC
Asked:
AngryC
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
Amir AzhdariCommented:
Hi,
First Save the HTML Code the a html File and try to load it by
WebBrowser1.Navigate('thefilename.html');
0
 
AngryCAuthor Commented:
Thanks but I think there's a direct way to do the thing without saving.
0
 
CesarioCommented:
Hi,

add this Function to your source code

procedure WB_LoadHTML(WebBrowser: TWebBrowser; HTMLCode: string);
var
  sl: TStringList;
  ms: TMemoryStream;
begin
  WebBrowser.Navigate('about:blank');
  while WebBrowser.ReadyState < READYSTATE_INTERACTIVE do
   Application.ProcessMessages;

  if Assigned(WebBrowser.Document) then
  begin
    sl := TStringList.Create;
    try
      ms := TMemoryStream.Create;
      try
        sl.Text := HTMLCode;
        sl.SaveToStream(ms);
        ms.Seek(0, 0);
        (WebBrowser.Document as IPersistStreamInit).Load(TStreamAdapter.Create(ms));
      finally
        ms.Free;
      end;
    finally
      sl.Free;
    end;
  end;
end;


best Regards

Cesario
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
atul_parmarCommented:
WebBrowser1.Stop;
WebBrowser1.Navigate('javascript:document.text=''<b>Hello</b>''');

Atul.
0
 
AngryCAuthor Commented:
Thanks guys.

Cesario,

Can you tell me what's the benefits of the following:

while WebBrowser.ReadyState < READYSTATE_INTERACTIVE do
   Application.ProcessMessages;

?
0
 
atul_parmarCommented:
Cesario,

If WebBrowser.ReadyState is less than READYSTATE_INTERACTIVE means that the browser might not initialized and it might not have loaded all of its properties. In this state ususally any interaction with the browser should be avoided.

The above code helps you to make sure that the browser is initialized and has loaded all of its properties and it is ready to process your request (e.g. requesting a web page etc.)
0
 
CesarioCommented:
Atul_parmar,

thanx for your comment :-)
0
 
AngryCAuthor Commented:
Ok, just one question more. Should I use Cesario's code or the following:

http://www.cryer.co.uk/brian/delphi/twebbrowser/put_HTML.htm
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now