dcef3 icon indicating copy to clipboard operation
dcef3 copied to clipboard

How to retrieve Javascript return value

Open shariful2011 opened this issue 8 years ago • 3 comments

I want to get return value of a javascript function after I execute it. How can I achieve it? Please help.

shariful2011 avatar Dec 08 '16 20:12 shariful2011

I don't know the proper way to do it, but i could achieve this task by using the OnConsoleMessage event of TChromium. So what i do is 'console.log' the result of my JS code, and grab it on this event.

For instance :

function sum(a,b) { var c = a + b; console.log(c); }

The 'c' result will be displayed at the console and you can grab it inside Delphi.

thefunkyjoint avatar Dec 09 '16 12:12 thefunkyjoint

Please somebody help us, I also use OnConsoleMessage event to communicate with web page script, but how to do this correctly without console?. And how to access DOM objects from TForm ? for example I need to access DOM window object, how i do this from a TForm function, like TButton OnClick ?

manopera avatar Dec 12 '16 19:12 manopera

Hello,

maybe this is the right way explained here: http://stackoverflow.com/questions/6893029/how-to-expose-native-functions-to-javascript-in-a-web-page-using-chromium-and

Unfortunately the register process fails on my machine because "strnlen" cannot be found withing the msvcrt.dll for some reason (I'm using a virtual machine with WinXP). So I can't verify it. :/

styxxx avatar Jan 24 '17 21:01 styxxx