Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/HTMLViewer Mac/JavaScript callback test
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/HTMLViewer Mac/JavaScript callback test
This example is the version from Sun, 17th Mar 2012.
Project "JavaScript callback test.rbp"
Filetype text
End FileTypes
Class MainWindow Inherits Window
Control Info Inherits Label
ControlInstance Info Inherits Label
End Control
Control web Inherits HTMLViewer
ControlInstance web Inherits HTMLViewer
End Control
Control Output Inherits Label
ControlInstance Output Inherits Label
End Control
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
EventHandler Sub TextChange() UpdateTimer.mode=1 End EventHandler
End Control
Control UpdateTimer Inherits Timer
ControlInstance UpdateTimer Inherits Timer
EventHandler Sub Action() run End EventHandler
End Control
EventHandler Sub Open() wui=new MyFrameEvents web.InstallWebFrameLoadDelegateMBS wui if not me.Composite then MsgBox "This window must be composite!" end if run End EventHandler
Protected Sub run() web.LoadHTMLStringMBS EditField1.text,"text/html","","http://www.monkeybreadsoftware.de" End Sub
Property Protected wui As myFrameEvents
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open() if TargetMachO then // ok else MsgBox "This project works only as MachO target on Mac OS X." end if callback=new MyScriptCallback MainWindow.show End EventHandler
Property callback As MyScriptCallback
End Class
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
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
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacControls Plugin.

MBS Xojo tutorial videos