Trigger FileMaker Scripts from JavaScript in FileMaker without fmp URL
For MacOS and iOS in FileMaker 16 or newer, you can use the WebKit message handler feature. First you call Webview.AddScriptMessageHandler function to register a name:
MBS( "Webview.AddScriptMessageHandler"; Name )
Next you can use it in Javascript to trigger a script in FileMaker from JavaScript:
And you can evaluate an expression in JavaScript:window.webkit.messageHandlers.test.postMessage({'filename':'WebView Message Handler.fmp12', 'parameter':'Hello World from JavaScript', 'scriptName':'test'});
As you see, we get for our message handler a new entry in the namespace called window.webkit.messageHandlers.test. This allows us to call postMessage method there and this triggers the plugin code to trigger scripts or do evaluation. The parameter to the postMessage must be a Javascript object with a few properties:window.webkit.messageHandlers.test.postMessage({'evaluate':'MBS( "Msgbox"; "Hello from Evaluate in JavaScript" )'});
- fileName: The name of the file with the script.
- scriptName: The name of the script to trigger.
- parameter: The parameter to pass to the script.
- evaluate: The expression to evaluation.
You can define a JavaScript function to wrap this and install it with WebView.RunJavaScript into the web viewer or include it in the html document:
Works in FileMaker Pro, Runtimes and in apps based on the FileMaker iOS SDK.function CallFileMaker(FileName, ScriptName, Parameter)
{
window.webkit.messageHandlers.test.postMessage({'filename': FileName, 'parameter': Parameter, 'scriptName': ScriptName });
}