« Xojo meetings in Ariz… | Home | MBS FileMaker Plugin,… »

JavaScript callback in HTMLViewer on Mac

Did you know you can register you own JavaScript callbacks for a HTMLViewer on Mac?

 

The WebScriptCallbackMBS class helps to handle such methods calls in JavaScript and redirects them to an event. In the Open event of the window, we add the WebFrameLoadDelegate to the HTMLViewer:

 

wui=new MyFrameEvents

web.InstallWebFrameLoadDelegateMBS wui

 

We need to subclass WebFrameLoadDelegateMBS in order to catch the windowScriptObjectAvailable event and add our MyBrowser object to the JavaScript name space:

 

Class MyFrameEvents Inherits WebFrameLoadDelegateMBS

EventHandler Function windowScriptObjectAvailable(windowScriptObject as WebScriptObjectMBS) As boolean

// Install an Object called "MyBrowser" on the javascript document object

// Any function call inside will tricker callback event

windowScriptObject.setWebScriptCallback "MyBrowser", app.callback

End EventHandler

End Class

 

Next we need to subclass WebScriptCallbackMBS class and fill the Callback event and do whatever our method should do:

 

Class MyScriptCallback Inherits WebScriptCallbackMBS

EventHandler Function Callback(Name as string) As variant

System.DebugLog "Function: "+name

Select case name

case "MsgBox"

MsgBox me.ArgumentValue(0)

case "PrintDialog"

call MainWindow.web.PrintDialogMBS

case "SetText"

MainWindow.Output.text=ArgumentValue(0)

end Select

End EventHandler

End Class 

 

As you our event can be called giving the name of the method called and the parameters can be queried via ArgumentValue function. The JavaScript call looks like this:

 

MyBrowser.SetText('Hello');

 

Sadly we can't provide the same for Windows so far. But Mac this is great already.

28 06 17 - 17:29