views:

622

answers:

3

I am coding a small app ,in middle i struck at some point where i have to execute javascript to get my data ?

in my process ,i have to login to some url and then go to some page and have to get data from that . i done all this with indy idhttp ,i got all info except one column which needs javascript to get value ,then i tried using twebbowser to make it work for me ,but how can i use cookies to enabled to webbrowser ?

i navigated browserto('http://mysite.com/login.php user and pass ') ,well its loged in and then i tried to access next link like ('http://mysite.com/link1/example.php')but it directing to login page :(

any help appreciated :)

A: 

http://www.delphidabbler.com/articles?article=21

chris
well i already seen that article sir ,my problem is getting that page into browser :S ,anyway thanks for reply
radick
Welcome to Stack Overflow. Although that link might be exactly the answer needed, nobody can possibly know without visiting it. To make this a good answer, please describe what visitors can expect to find at that link. Summarize its contents if you can. Prove that you did more than just paste the first link Google gave you. At the *very least*, give the page title in addition to the link.
Rob Kennedy
+2  A: 

What is your question now? In the title you ask how to execute JavaScript. Try the following:

uses
  MSHTML_TLB, SHDocVw, ShellAPI;

function ExecuteScript(doc: IHTMLDocument2; script: string; language: string): Boolean;
var
  win: IHTMLWindow2;
  Olelanguage: Olevariant;
begin
  if doc <> nil then
  begin
    try
      win := doc.parentWindow;
      if win <> nil then
      begin
        try
          Olelanguage := language;
          win.ExecScript(script, Olelanguage);
        finally
          win := nil;
        end;
      end;
    finally
      doc := nil;
    end;
  end;
end;

Sample usage:

IDoc: IHTMLDocument2;
Webbrowser1.Document.QueryInterface(IHTMLDocument2, iDoc);
ExecuteScript(iDoc, 'document.login.submit()', 'JavaScript'); 

(This, and more, can be found here).


Then in the text you ask how to use cookies (when using TWebBrowser this should happen automatically). When using Indy HTTP, you just have to attach a TIdCookieManager to your TIdHTTPClient instance, thats all (but you probably don't want to use that anyway, due to the script requirement....)

Mef
A: 

Your best bet would be to automate IE itself. Grab a copy of embeddedwb, drop on a form and navigate to the url which you need to execute something. There is a document property of the component which returns an OLEVariant, use this to execute a DHTML style statement.. something like document.form.submit;.

You can easily hide the window used for automation, one technique I have used is to place it on a new page on a page control, add a second page to display the status, then show the status page and hide the tabs.

skamradt