Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
12.1
12.2
12.3
12.4
12.5
13.0
13.1
13.2
13.3
13.4
Statistic
FMM
Blog
Evaluates a JavaScript expression.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
Webview | 10.0 | ✅ Yes | ✅ Yes | ❌ No | ❌ No | ✅ Yes |
Parameter | Description | Example |
---|---|---|
WebViewerRef | Either the Web Viewer Object Name or the Web Viewer ID as returned by "WebView.FindByName" function. | |
Expression | The JavaScript expression to evaluate. | "1+" |
Returns value or error.
Evaluate an expression:
MBS( "WebView.Evaluate"; "web"; "1+2" )
Build some JavaScript object and return as JSON:
MBS("WebView.Evaluate"; "web"; "var obj = { name: \"John\", age: 30, city: \"New York\" };
JSON.stringify(obj);")
Defines and runs a function in JavaScript in the web viewer:
MBS("WebView.Evaluate"; "web";
"function makeCRCTable(){
var c;
var crcTable = [];
for(var n =0; n < 256; n++){
c = n;
for(var k =0; k < 8; k++){
c = ((c&1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
}
crcTable[n] = c;
}
return crcTable;
}
function crc32(str) {
var crcTable = crcTable || (crcTable = makeCRCTable());
var crc = 0 ^ (-1);
for (var i = 0; i < str.length; i++ ) {
crc = (crc >>> 8) ^ crcTable[(crc ^ str.charCodeAt(i)) & 0xFF];
}
return (crc ^ (-1)) >>> 0;
};
crc32('Hello World');")
Fill a search form, submit and query result:
# load website with search field:
Set Web Viewer [ Object Name: "web" ; URL: "https://something.com/searchpage" ]
#
# wait for website to finish loading
Pause/Resume Script [ Duration (seconds): ,5 ]
Loop
Exit Loop If [ MBS("WebView.IsLoading"; "web") ≠ 1 ]
Pause/Resume Script [ Duration (seconds): ,1 ]
End Loop
Pause/Resume Script [ Duration (seconds): ,5 ]
#
# fill in search term and send change event, so this website sees it:
Set Variable [ $r ; Value: MBS("WebView.RunJavaScript"; "web"; "document.getElementById('searchField').value = '" & Substitute ( Web::SearchTerm ; "'" ; "" ) & "'") ]
Set Variable [ $r ; Value: MBS("WebView.RunJavaScript"; "web"; "var o = document.getElementById('searchField'); var evt = document.createEvent('Events'); evt.initEvent('change', true, true); o.dispatchEvent(evt); }") ]
#
# wait a bit
Pause/Resume Script [ Duration (seconds): ,5 ]
#
# send click event to search button
Set Variable [ $r ; Value: MBS("WebView.RunJavaScript"; "web"; "var o = document.getElementById('searchButton'); var evt = document.createEvent('Events'); evt.initEvent('click', true, true); o.dispatchEvent(evt); ") ]
#
# wait for website to finish loading
Pause/Resume Script [ Duration (seconds): ,5 ]
Loop
Exit Loop If [ MBS("WebView.IsLoading"; "web") ≠ 1 ]
Pause/Resume Script [ Duration (seconds): ,1 ]
End Loop
Pause/Resume Script [ Duration (seconds): ,5 ]
#
# query values from website
Set Field [ Web::articleId ; MBS("WebView.Evaluate"; "web"; "document.getElementById('articleId').innerText;") ]
Set Field [ Web::price ; MBS("WebView.Evaluate"; "web"; "document.getElementById('price').innerText;") ]
Wait for field named Remember to show up on website:
Pause/Resume Script [ Duration (seconds): 1 ]
Set Variable [ $count ; Value: 0 ]
Loop
Set Variable [ $r ; Value: MBS("WebView.Evaluate"; "web"; "(null == document.getElementById('Remember'))") ]
Exit Loop If [ $r = 0 ]
Pause/Resume Script [ Duration (seconds): 1 ]
Set Variable [ $count ; Value: $count + 1 ]
If [ $count = 20 ]
Show Custom Dialog [ "Timeout" ; "Failed to load website and get the remember checkbox." ]
Exit Script [ Text Result: ]
End If
End Loop
Pause/Resume Script [ Duration (seconds): 1 ]
# now you can set/query it
Query scroll position via JavaScript:
MBS( "WebView.Evaluate"; "web"; "document.scrollingElement.scrollTop" )
Run FileMaker's message handler in FileMaker 19:
MBS( "WebView.Evaluate"; "web"; "if (typeof(FileMaker) != 'undefined') { FileMaker.PerformScript('test', 'Hello'); r = 'OK'; } else { r = 'Failed'; }; r;")
// returns OK on success or Failed if not.
Check if FileMaker 19 message handler is installed:
MBS( "WebView.Evaluate"; "web"; "typeof(FileMaker)")
// returns "object" if installed or "undefined"
Query browser version:
MBS("Webview.Evaluate"; "web"; "navigator.appVersion")
Example result: "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36 Edg/89.0.774.75"
Query html of an element on the website:
Set Variable [ $html; Value: MBS( "WebView.Evaluate"; "web"; "document.getElementById('maintop').outerHTML" ) ]
This function checks for a license.
Created 4th January 2020, last changed 18th July 2022