Is this broken?

I added a simple chat container. Along the way I was trying to add html to inner html. Would not run ExecuteJavascript for the other container in the array. So I tried a simple test using just this code.

App.ChatConts(i).ExecuteJavaScript("alert('hello')")

I know the App.ChatConts has properly appended of the containers and it will do things like App.ChatConts(i).TextField_Message.text = “Test” and display test properly on each of the pages. However, the ExecuteJavascript will not run in each one of the chat containers. Is ExecuteJavascript broken??? Not sure what Im doing wrong. Thanks for any information.

If I use App.ChatConts(i).ChatViewer.LoadHTML(“test”) it loads on each of the container pages for the each different session. Why doesnt ExecuteJavaScript work the same?

Any help at all to give me some sort of direction?

I think you’re missing the semicolon ; at the end of the statement so try:
ExecuteJavaScript("alert('hello');")

1 Like

The semicolon is optional

So can anyone tell me if ExecuteJavascript only works for the current session?

everthing happens in the session context (current session) if you call ExecuteJavascript. It’s NOT called for ALL sessions if you mean that.

I would like to call it from another session to add html into a viewer. Whenever I call it in another session, it doesn’t work properly. That session calls for my current session. Basically what I am doing is using the chat example project but instead of a listbox I’m using an html viewer. Instead of .addrow I’m using executeJavascript to insert a an html row into the viewer. But when I call executeJavascript, the row inserts on my session, but when it should insert on the other session, it inserts on my session again.

See Page Not Found — Xojo documentation

Edit to add: in the latest Xojo, you have to do this server-side, not inside a Session event.

Here’s some code I wrote to force all users offline:

WebPage.Button1.Pressed
   // the method needs to run outside this current WebSession, so we use a timer to get it to run on the App's main thread:
   Timer.CallLater(1, AddressOf app.ForceUsersOffline)

App:
Public Function ForceUsersOffline()

  // forces all users to the offline status
  system.DebugLog "*** Forcing all users Offline, except for administrators"
  

  #Pragma DisableBackgroundTasks
  For i As Integer = 0 To App.SessionCount - 1
    dim sess as session = App.SessionAt(i)
    
   // don't kick administrators offline
    if sess = nil or sess.isAdministrator then  // isAdministrator is my own function
      continue
    end if
    
    // Without creating a WebSessionContext here, creating
    // the page would fail triggering a SessionNotAvailableException.
    Var context As New WebSessionContext(sess)
    // Because we have a context, we can create a new
    // WebPage and assign it to the session.
    context.Session.CurrentPage = new wOfflineWebpage
    // the end result is the user is sent to the new page

    // you could also do something else, such as
    dim wp as WebPage = context.Session.CurrentPage
    if wp isa WebPage1 then
        WebPage1(wp).ExecuteJavascript("alert('hello')")
    end if

  Next

End Function
1 Like