ExecuteJavascript can't be used in a method of a module.

ExecuteJavaScript in a method of a module in a WebApplication produce the error:

This item does not exist
A reference to a WebControl or a variable declared as a WebControl compile without errors.

It seems to me an odd behaviour…

Won’t you post your code ?

Sub Test() dim s As String = "alert('Hello!')" executeJavascript(s) End Sub

Hi Michel, the error shows up also on your side?

You can use any object which you have in your project to call javascript. For example webpage1.executejavascript(s)

Thank you Krystof.
Your workaround works BUT ExecuteJavascript in the docs is reported as a method, not as something tied to a webcontrol or webobject.

A compiler glitch?

But the docs say right here that it’s a method for a WebControl?
http://documentation.xojo.com/index.php/WebControl.ExecuteJavaScript

[quote=268024:@Maurizio Rossi]Sub Test()
dim s As String = “alert(‘Hello!’)”
executeJavascript(s)
End Sub[/quote]

Your error is not to indicate where to execute JavaScript.

On a window, executeJavaScript is synonymous with self.executeJavaScript.

In a module, self does not mean anything. So you must pass the page to the method.

Sub Test(WP as Webpage) dim s As String = "alert('Hello!')" WP.executeJavascript(s) End Sub

Test(WP)

Maybe a little clarification in the documentation will be nice.
Is a simple glitch…

ExecuteJavaScript as a method …

http://documentation.xojo.com/index.php/WebControl.ExecuteJavaScript

?

Never mind. Execute what you want.

??

That page states clearly

But as Michel stated I Execute what I want…

This is EXACTLY the kind of professional comments that someone feels the need to post…

[quote=268092:@Tim Hare]That page states clearly

The JavaScript passed can call a JavaScript function in a WebPageSource control.[/quote]
That is not correct. I can understand Maurizio’s question. Shouldn’t the page be titled WebPageSource.ExecuteJavaScript?[/url]
But the page title is ExecuteJavaScript only, so it raises the impression that it can be called as a (global) function not tied to a class.

I took the time to explain WHY as the thread is entitled "ExecuteJavascript can’t be used in a method of a module. ". That should probably be in the LR, but it never hurts either when one gets a detailed answer to acknowledge it and show courtesy. Heck, a simple like would suffice ! No need to be professional to be polite.

https://forum.xojo.com/32130-ignore-them/0

[quote=268098:@Eli Ott]That is not correct. I can understand Maurizio’s question. Shouldn’t the page be titled WebPageSource.ExecuteJavaScript?[/url]
But the page title is ExecuteJavaScript only, so it raises the impression that it can be called as a (global) function not tied to a class.[/quote]
No. ExecuteJavascript is a method on the WebControl and WebSession classes. Any subclasses of those controls also have direct access to ExecuteJavascript. Because of this, it appears to be a global method, but it’s really not… and for good reason… because it needs to know which session to send the command to.

You could just as easily run it as Self.ExecuteJavascript from within a method of any WebControl.

I think the docs should be amended to reflect that.