ExecuteJavaScript - how to obtain return value?

Dear all,

ExecuteJavaScript works fine for one-way communication. However, how can an expected return value of an executed JS function be obtained?

Thanks, Alex

The MonkeyBreadSoftware (MBS) plugins have some methods to do this.

Another way: the Document.title hack. Change document.title in the javascript to return the value, then use the htmlviewer.titleChanged event to capture the result. Not elegant, but does work.

You have to think asynchronously. So something like this would never work for you in a WE application:

x = ExecuteJavascript(myScript)

The most straightforward approach is to use the WebSDK and make a custom control out of whatever you’re doing. Send the script (server), Trigger an event (browser), Raise an event (server).

If you want to get clever, I have a “clever” approach in Studio Stable Web Essentials.

Oops, I didn’t notice this was a WEB target and was assuming you were talking about HTMLViewers on Desktop - ignore my suggestion, sorry.

[quote=21120:@Brad Hutchings]You have to think asynchronously. So something like this would never work for you in a WE application:

x = ExecuteJavascript(myScript)

The most straightforward approach is to use the WebSDK and make a custom control out of whatever you’re doing. Send the script (server), Trigger an event (browser), Raise an event (server).

If you want to get clever, I have a “clever” approach in Studio Stable Web Essentials.[/quote]

That is what I am doing; but: I am calling a function supplied by a framework, and it gives me no opportunity to add a callback… Is there another way to add a callback to a generic JS function without modifying external source code?

No. Brad’s response is right on the money.

Hmm, okay. Let’s say I am wrapping a JS control. How can I call a fuction with a return value of this JS control without modifying it’a code - using Brad’s hints?

if you need it i can make a class that returns a value from an event.
Just say and i’ll create it for you using WebSDK

Events are no problem, I catch them with EventListeners. It’s the return of a predefined JS fuction, which I am not in control of or I can alter, that I want to catch.

Write your own JS code wrapper and then you can use Brad’s answer…?

Why do you want the value back to the server? Can’t you just handle it inside javascript?

No, not all of the logic. But I am writing my own JS wrapper :slight_smile: