...append HTML Text to a TWebbrowser Document?
2006-01-31 23:12
337 查看
http://www.swissdelphicenter.ch/en/showcode.php?id=2148
{1. ----------------------------------------------------------------}
uses
MSHTML;
procedure TForm1.Button1Click(Sender: TObject);
var
Range: IHTMLTxtRange;
begin
Range := ((WebBrowser1.Document as IHTMLDocument2).body as
IHTMLBodyElement).createTextRange;
Range.collapse(False);
Range.pasteHTML('<br><b>Hello!</b>');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Webbrowser1.Navigate('www.google.ch');
end;
{----------------------------------------------------------------}
{2. ----------------------------------------------------------------}
unit Unit1;
// by Sprint
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, MSHTML, StdCtrls;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private-Deklarationen }
FirstRun: Boolean;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{----------------------------------------------------------------}
procedure TForm1.FormCreate(Sender: TObject);
begin
FirstRun := True;
WebBrowser1.Navigate('about:blank');
end;
{----------------------------------------------------------------}
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
WebDoc: HTMLDocument;
WebBody: HTMLBody;
begin
if FirstRun then
if pDisp = WebBrowser1.Application then
begin
FirstRun := False;
WebDoc := WebBrowser1.Document as HTMLDocument;
WebBody := WebDoc.body as HTMLBody;
WebBody.insertAdjacentHTML('BeforeEnd', '<h1>Hello World!</h1>');
end;
end;
{----------------------------------------------------------------}
end.
{1. ----------------------------------------------------------------}
uses
MSHTML;
procedure TForm1.Button1Click(Sender: TObject);
var
Range: IHTMLTxtRange;
begin
Range := ((WebBrowser1.Document as IHTMLDocument2).body as
IHTMLBodyElement).createTextRange;
Range.collapse(False);
Range.pasteHTML('<br><b>Hello!</b>');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Webbrowser1.Navigate('www.google.ch');
end;
{----------------------------------------------------------------}
{2. ----------------------------------------------------------------}
unit Unit1;
// by Sprint
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, MSHTML, StdCtrls;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private-Deklarationen }
FirstRun: Boolean;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{----------------------------------------------------------------}
procedure TForm1.FormCreate(Sender: TObject);
begin
FirstRun := True;
WebBrowser1.Navigate('about:blank');
end;
{----------------------------------------------------------------}
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
WebDoc: HTMLDocument;
WebBody: HTMLBody;
begin
if FirstRun then
if pDisp = WebBrowser1.Application then
begin
FirstRun := False;
WebDoc := WebBrowser1.Document as HTMLDocument;
WebBody := WebDoc.body as HTMLBody;
WebBody.insertAdjacentHTML('BeforeEnd', '<h1>Hello World!</h1>');
end;
end;
{----------------------------------------------------------------}
end.
相关文章推荐
- append HTML Text to a TWebbrowser Document?
- JQuery.html()与jquery.append(document.createTextNode())的区别
- jQuery JavaScript Library v1.6.1的$(document.body).append(html)不支持ie
- How to read a text file attached to a Lotus Notes Document WITHOUT detaching it?
- Save or append text to a file (c#)
- document.write() 和(对象名).innerText=" " / innerHTML=""对于当前文档流的影响小结
- The Easy Way to Extract Useful Text from Arbitrary HTML
- HtmlText To Excel
- C# Html to Text
- Convert HTML to Plain Text (把HTML文本转换成纯文本)
- Two ways to get HtmlTextWriter for HTML rendering
- 拉动滚动条追加内容,无限延伸document高度 $(window).scroll(function(){if($(window).scrollTop() + $(window).height() == $(document).height()) { $("body").append(html) } })
- http://ai-depot.com/articles/the-easy-way-to-extract-useful-text-from-arbitrary-html/
- JS. How to replace html element with another element/text, represented in string?
- Append text to TextArea in the currentcursor position
- Text to Html
- [Cocoa]convert html to plain text
- dom4j:Adding text to an XML document must not be null
- jquery获取动态生成的元素【live(), on()】div text html append attr
- How to get IHTMLDocument2 from a HWND