Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

TWebBrowser paste u formu i klik na gumb

[es] :: Pascal / Delphi / Kylix :: TWebBrowser paste u formu i klik na gumb

[ Pregleda: 1502 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

captPicard
programer
more i planine

Član broj: 216084
Poruke: 1119



+19 Profil

icon TWebBrowser paste u formu i klik na gumb01.12.2011. u 16:53 - pre 150 meseci
Dakle, želim napraviti Paste texta iz clipboarda u određenu formu na web stranici koja je učitana u twebbrowseru i kliknuti na gumbić.

Ako može pomoć, bio bi zahvalan :)

Hvala.
F
 
Odgovor na temu

salaczr

Član broj: 160654
Poruke: 103
*.dynamic.isp.telekom.rs.



+5 Profil

icon Re: TWebBrowser paste u formu i klik na gumb02.12.2011. u 12:40 - pre 150 meseci
Da bi pronasao koji deo ucitane stranice je aktivan mozes da koristis CommandStateChangeEvent
Code:

procedure TForm1.CommandStateChangeEvent(Sender: TObject; Command: Integer;
  Enable: WordBool);
begin
  case TOleEnum(Command) of
    CSC_UPDATECOMMANDS :
      begin
         if ((Sender as TWebBrowser).ReadyState = READYSTATE_COMPLETE) then
            if (((Sender as TWebBrowser).Document as IHTMLDocument2).activeElement.tagName = 'INPUT') or
               (((Sender as TmWebBrowser).Document as IHTMLDocument2).activeElement.tagName = 'TEXTAREA')
            then
                begin
                   // Ovde uradis sta zelis
                end;
      end;
  end;
end;

da bi promenio sadrzaj ucitane stranice moras da ukljucis DesignMode na DocumentComplete event

Code:

procedure TForm1.DocumentComplete(Sender: TObject;
   const pDisp: IDispatch; var URL: OleVariant) ;
begin
   ((Sender as TWebBrowser).Document as IHTMLDocument2).designMode := 'on';
end;

ako zelis da pokreces svoje JS f-je mozes da pokusas sledece:

Code:

procedure ExecuteScript(doc: IHTMLDocument2; script: string; language: string) ;
begin
  if doc <> nil then
  begin
  if doc.parentWindow <> nil then
  doc.parentWindow.ExecScript(script, Olevariant(language)) ;
  end;
end;

Posle samo pozoves f-ju iz Delphi-ja

Code:

ExecuteScript(WebBrowser1.Document as IHTMLDocument2, script, 'javascript');  

ako zelis da pozivas neki JS iz samog html-a koji si ucitao u WebBrowser kontrolu evo primera:

Code:

uses
  MSHTML;

procedure TForm1.CallFoo(S: string; I: Integer);
  { Calls JavaScript foo() function }
var
  Doc: IHTMLDocument2;      // current HTML document
  HTMLWindow: IHTMLWindow2; // parent window of current HTML document
  JSFn: string;             // stores JavaScipt function call
begin
  // Get reference to current document
  Doc := WebBrowser1.Document as IHTMLDocument2;
  if not Assigned(Doc) then
    Exit;
  // Get parent window of current document
  HTMLWindow := Doc.parentWindow;
  if not Assigned(HTMLWindow) then
    Exit;
  // Run JavaScript
  try
    JSFn := Format('foo("%s",%d)', [S, I]);  // build function call
    HTMLWindow.execScript(JSFn, 'JavaScript'); // execute function
  except
    // handle exception in case JavaScript fails to run
  end;
end;


Nadam se da sam ti pomogao.

pozdrav
 
Odgovor na temu

[es] :: Pascal / Delphi / Kylix :: TWebBrowser paste u formu i klik na gumb

[ Pregleda: 1502 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.