Novo

Forum kao aplikacija na telefonu

Dodajte forum na početni ekran i koristite ga kao aplikaciju, sa menijem na dnu ekrana.

  • 1 odgovor
  • 1.958 pregleda

Najnovija ↓

TWebBrowser paste u formu i klik na gumb 01.12.2011. u 17:53 · pre 181 mesec #1
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.
Potpis
F
Re: TWebBrowser paste u formu i klik na gumb 02.12.2011. u 13:40 · pre 181 mesec #2
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
Prijavite se da biste odgovorili u ovoj temi.PrijavaRegistracija

Premeštanje teme