Call JavaScript in a TWebBrowser and get a result back
Calling a JavaScript function in a TWebBrowser is easy, but getting a return value from it is hard. I've been struggling for ages to find an answer to this, and lots of users have asked. My article " How to call JavaScript functions in a TWebBrowser from Delphi " goes into details. Christian Sciberras suggested a solution that depended on modifying the HTML source to include a hidden input field and modifying the function stores its result in the field. I've wanted a tidier solution that didn't involve changing either the HTML code or the JavaScript function, because we can't always do that. I've now got a solution based on Christian's: Create a hidden input field in the current document with a unique id. Wrap the required function call in JavaScript that calls the function and stores its return value in the input field. Read the value from the input field and return it. It's a bit of a dirty hack, and it only works if the function...