How to return a value from ExecuteJavaScript?

Hello all,

This is my first excursion into Javascript. I am wanting to get the browser inner width and heigth.

sub getBrowserInnerWindow(wp as webpage)
    wp.ExecuteJavaScript(" window.innerWidth")
End sub

When I try to code the above as w = wp.ExecuteJavaScript(" window.innerWidth"), I get a compiler error saying that the ExecuteJavascript does not return a value. So how do I get a returned value?

This link shows the following code, which works in their website, but I do not know now to translate that to Xojo.

var txt = “”;
txt += "

innerWidth: " + window.innerWidth + “

txt += "

innerHeight: " + window.innerHeight + “

txt += "

outerWidth: " + window.outerWidth + “

txt += "

outerHeight: " + window.outerHeight + “


I looked through the docs but cannot find any mention of how to get a return value. I have a really hard time with the new docs too.
Any help would be appreciated!

The short answer: You can’t.

The long answer: Use Xojo.TriggerServerEvent in your JS to send the requested data back to your app. You’ll need to create a WebControlWrapper subclass to pull this off. Check out the WebSDK for more info.

Hi Anthony, good to see you again here on the forum. I hope you feel well again!!

There is a simpler way to return a value, using Hashtag. See

While I can see the benefit of using Hashtag in certain situations, I think that functions like this would probably be best served as a WebControlWrapper. It really depends on what they want to accomplish, though. If they want to monitor the innerWidth and innerHeight to make some sort of global change, then Hashtag would likely be preferred. If they want to monitor for a specific change to a specific area of their application, WebControlWrapper is probably better. Again, not sure what they want to use the calculations for.

Either way, they get the desired result.

Thanks everyone for your responses!
@Anthony - What I am trying to do is to get the starting inner width and height of the browser, so I know the size of the applications page. Currently no matter how hard I try, I can only get the design time size of the page - until a resize is done twice (once to make the browser smaller, then go back to full screen). Once a resize is done twice, I get the real size of the apps page.

Based on other posts, and one where Michel suggested using the ExecuteJavaScript to get Window.InnerWidth and InnerHeight I thought I would give it a try…

It is really a one time, start up use. Not continuous.