How to get JavaScript return?

705 views
Skip to first unread message

Walter Souza

unread,
Feb 24, 2011, 2:53:14 PM2/24/11
to delphichrom...@googlegroups.com
Hello,

I wanna know how can I execute a javascript and get the response in my Delphi variable.

Thans in advance!!

Henri Gourvest

unread,
Feb 24, 2011, 4:34:01 PM2/24/11
to delphichrom...@googlegroups.com
Hi,

If you are using Delphi 2010 and higher it is quite easy:
First get the latest version from SVN trunk

// this execute a javascript code
Browser.MainFrame.ExecuteJavaScript('app.doit(''foo'')', '', 0);

// this is your class exposed to JS
  Test = class
    class procedure doit(const v: string);
  end;

initialization
// Register your class
  TCefRTTIExtension.Register('app', Test, True);

It also work with objects and it is able to synchronyse JS calls with main thread.

If you are using other compilers it will be a bit harder,
take a look on the cefclient.dpr demo application and the TExtension class.



2011/2/24 Walter Souza <wsou...@gmail.com>

Hello,

I wanna know how can I execute a javascript and get the response in my Delphi variable.

Thans in advance!!



--
Henri Gourvest

Walter Souza

unread,
Feb 28, 2011, 1:39:41 PM2/28/11
to delphichromiumembedded
Hello Henri,

Unfortunately I'm using Delphi 7, I will try to transcribe the 2010
version..

If you have some tips, I'm ready to hear!!

Thanks for all.

On Feb 24, 6:34 pm, Henri Gourvest <hgourv...@gmail.com> wrote:
> Hi,
>
> If you are using Delphi 2010 and higher it is quite easy:
> First get the latest version from SVN trunk
>
> // this execute a javascript code
> Browser.MainFrame.ExecuteJavaScript('app.doit(''foo'')', '', 0);
>
> // this is your class exposed to JS
>   Test = class
>     class procedure doit(const v: string);
>   end;
>
> initialization
> // Register your class
>   TCefRTTIExtension.Register('app', Test, True);
>
> It also work with objects and it is able to synchronyse JS calls with main
> thread.
>
> If you are using other compilers it will be a bit harder,
> take a look on the cefclient.dpr demo application and the TExtension class.
>
> 2011/2/24 Walter Souza <wsouz...@gmail.com>

Henri Gourvest

unread,
Feb 28, 2011, 5:33:14 PM2/28/11
to delphichrom...@googlegroups.com
no don't try to read the Delphi 2010 helper class, 
take a look on the cefclient.dpr demo application and the TExtension class !

2011/2/28 Walter Souza <wsou...@gmail.com>



--
Henri Gourvest

Walter Souza

unread,
Mar 22, 2011, 9:48:06 AM3/22/11
to delphichromiumembedded
Thanks for all Henry,

I take sometime to get back to project, but now I write my own
extension and it works perfectly.

So Thankful,

On Feb 28, 7:33 pm, Henri Gourvest <hgourv...@gmail.com> wrote:
> no don't try to read the Delphi 2010 helper class,
> take a look on the cefclient.dpr demo application and the TExtension class !
>
> 2011/2/28 Walter Souza <wsouz...@gmail.com>
Reply all
Reply to author
Forward
0 new messages