Using SetTimeOut function in Javascript with Xojo

Hi folks.

I dunno If I’m doing something wrong. I’m trying to use “SettimeOut” Javascript function to delay the execution of a method. For example after 4000 miliSeconds do something, example:

Dim Verify500 As String = “setTimeout(testmethod, 4000);” _
+“function testmethod() {” _
+" return ‘hallo welt!’;" _
+"}"

Msgbox HTMLViewer1.EvaluateJavaScriptMBS(Verify500)

After 4000 milliseconds should display the messagebox saying “Hallo Welt”.
But it doesn’t happen, instead of this, It behaves at this way:

When I press the button automatically Shows a messagebox with “1”, If I press it again says “2”, again “3”, again “4”, and so on.

Thanks.

HTMLViewer runs asynchronously to Xojo - it’s one of the main challenges with HTML Edit.

You’d probably get a result close to what you want by using the Window.Status trick, but it wouldn’t halt execution - you would get the result 4000ms later in HTMLViewer.StatusChagned, assuming the main thread was free.

A more controlled solution would be to execute the JavaScript at the time you want within Xojo instead.

If EvaluateJavaScriptMBS works like the OS X framework call (probable), it works without Return :

Dim Verify500 As String = "setTimeout(testmethod, 4000);" _ +"function testmethod() {" _ +"'hallo welt!';" _ +"}"

See https://forum.xojo.com/22633-get-javascript-variables-back-from-htmlviewer-without-changing-

Although I am not too sure that method works with a timer.

I quickly dropped that method, as it does not support multiple or sequential variable return. StatusChanged is IMHO much more flexible. With StatusChanged, you can perfectly well return variables in a loop, or at any moment, from anywhere, even by attaching events to elements.

[quote=241176:@Michel Bujardet]If EvaluateJavaScriptMBS works like the OS X framework call (probable), it works without Return :

Dim Verify500 As String = "setTimeout(testmethod, 4000);" _ +"function testmethod() {" _ +"'hallo welt!';" _ +"}"

See https://forum.xojo.com/22633-get-javascript-variables-back-from-htmlviewer-without-changing-

Although I am not too sure that method works with a timer.

I quickly dropped that method, as it does not support multiple or sequential variable return. StatusChanged is IMHO much more flexible. With StatusChanged, you can perfectly well return variables in a loop, or at any moment, from anywhere, even by attaching events to elements.[/quote]
I tried without Return and nothing happens.

Also I thought in doing a “for” loop but nothing.

And about window.status, remember that already exists that windows issue

[quote=241196:@Gerardo García]I tried without Return and nothing happens.

Also I thought in doing a “for” loop but nothing.

And about window.status, remember that already exists that windows issue[/quote]

EvaluateJavaScript exists only on Mac, so StatusChanged works there quite well.

On Windows you can use TitleChanged for the same purpose. Or CancelLoad.

At any rate since you are using an MBS plugin maybe you want to ask Christian.

Try moving the definition of the function to before you use it in the SetTimeout. I have a feeling that you’re redefining it after you use it.

To be fair, your method doesn’t do anything. Of you want a dialog, you need the alert method.