Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides
New in version: 5.4   6.0   6.1   6.2   6.3   6.4   6.5   7.0   7.1   7.2    Statistic  

WebView.RunJavaScript

Executes the Javascript on the specified webViewer control.

Component: WebView
Version: 1.3
Mac OS X: Yes
Windows: Yes
Server: No
FileMaker Cloud: No

MBS( "WebView.RunJavaScript"; WebViewerRef; Javascript )

Parameters

Parameter Description Example value
WebViewerRef Either the Web Viewer Object Name or the Web Viewer ID as returned by "WebView.FindByName" function.
Javascript The Javascript to be executed

Description

Executes the Javascript on the specified webViewer control.
Allows you to call any Javascript function that is in loaded in the WebViewer OR you can just run arbitrary JavaScript on an empty web page. The results of the JavaScript are returned on Macintosh only. There is another function called WebView.RunJavaScriptReturnTitle which can be used to return the value of a Javascript function on both platforms. Use "\n" in javascript strings for a newline character.

Examples

Set the htmlcode of a field as string:

MBS( "WebView.RunJavaScript"; "browser"; "document.getElementById('td_ProcName_v').innerHTML='hello';" )

Run JavaScript

Let(
[

// very simple javascript

javascript = "alert('OK');";

webViewerName = "myWebViewer";
windowRef = MBS("Window.FindByTitle"; Get ( WindowName ));
webViewerID = MBS("WebView.FindByName"; windowRef; webViewerName)

];
Case(
webViewerID = 0; "Web Veiwer \"" & webViewerName & "\" Not Found: " &windowRef ;

MBS("WebView.RunJavaScript"; webViewerID; javaScript)

)

)

Start a video inside an interactive container on Mac:

MBS( "WebView.RunJavaScript" ; "movie"; "document.getElementsByTagName('video')[0].play();" )

Send change event to send to a field with ID $FieldID so javascript code on webpage knows we changed something:

MBS( "WebView.RunJavaScript" ; "web"; "var o = document.getElementById('" & $FieldID & "');
        if (document.createEvent) {
                var evt = document.createEvent('Events');
                evt.initEvent('change', true, true);
                o.dispatchEvent(evt); }")

Clear onBeforeLoad event handler:

MBS( "WebView.RunJavaScript" ; "HTMLEditor"; "window.onbeforeunload = null;")

Send click event:

MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].loginButton;
        if (document.createEvent)
        {
                var evt = document.createEvent('Events');
                evt.initEvent('click', true, true);
                o.dispatchEvent(evt);
          }")

Filling a complex form of a web app with help of Javascript:

# go to Vouchers
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.getElementsByClassName('appGlobalSideNav')[0].getElementsByTagName('a')[2]; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('click', tr… ]
Pausa/continua lo script [ Durata (secondi): ,3 ]
# open popup
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "document.getElementsByClassName('appMainButton')[0].click();") ]
Pausa/continua lo script [ Durata (secondi): ,3 ]
# Set Values in various fields and trigger change/click events
Imposta variabile [ $r ; Valore: MBS( "WebView.SetFormInputValue" ; "browser"; "vouchersCreateCtrl.form"; "number"; "1") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].number; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('change', true, true); o.dispatchEvent(evt); }") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.SetFormSelectValue" ; "browser"; "vouchersCreateCtrl.form"; "quota"; "0") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.SetFormSelectValue" ; "browser"; "vouchersCreateCtrl.form"; "expire"; "custom") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].expire; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('change', true, true); o.dispatchEvent(evt); }") ]
Pausa/continua lo script [ Durata (secondi): ,3 ]
Imposta variabile [ $r ; Valore: MBS( "WebView.SetFormInputValue" ; "browser"; "vouchersCreateCtrl.form"; "expire_number"; "2") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.SetFormSelectValue" ; "browser"; "vouchersCreateCtrl.form"; "expire_unit"; "1440") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].expire_number; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('change', true, true); o.dispatchEvent(evt); }") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "document.forms[0].limitDownload.checked = true;") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].limitDownload; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('click', true, true); o.dispatchEvent(evt); }") ]
Pausa/continua lo script [ Durata (secondi): ,1 ]
Imposta variabile [ $r ; Valore: MBS( "WebView.SetFormInputValue" ; "browser"; "vouchersCreateCtrl.form"; "down"; "512") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].down; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('change', true, true); o.dispatchEvent(evt); }") ]
Pausa/continua lo script [ Durata (secondi): ,1 ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "document.forms[0].limitUpload.checked = true;") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].limitUpload; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('click', true, true); o.dispatchEvent(evt); }") ]
Pausa/continua lo script [ Durata (secondi): ,1 ]
Imposta variabile [ $r ; Valore: MBS( "WebView.SetFormInputValue" ; "browser"; "vouchersCreateCtrl.form"; "up"; "512") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].up; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('change', true, true); o.dispatchEvent(evt); }") ]
Pausa/continua lo script [ Durata (secondi): ,1 ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "document.forms[0].byteQuota[0].checked = true;") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].byteQuota[0]; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('click', true, true); o.dispatchEvent(evt); }") ]
Pausa/continua lo script [ Durata (secondi): ,1 ]
Imposta variabile [ $r ; Valore: MBS( "WebView.SetFormInputValue" ; "browser"; "vouchersCreateCtrl.form"; "byteQuota"; "123") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].byteQuota[1]; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('change', true, true); o.dispatchEvent(evt); }") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.SetFormInputValue" ; "browser"; "vouchersCreateCtrl.form"; 8; "CLIENTE") ]
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].elements[11]; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('change', true, true); o.dispatchEvent(evt); }") ]
Pausa/continua lo script [ Durata (secondi): ,3 ]
# press save button
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "var o = document.forms[0].elements[13]; if (document.createEvent) { var evt = document.createEvent('Events'); evt.initEvent('click', true, true); o.dispatchEvent(evt); }") ]
Pausa/continua lo script [ Durata (secondi): ,3 ]
# find the voucher ID and save it to field.
Imposta variabile [ $r ; Valore: MBS( "WebView.RunJavaScript" ; "browser"; "document.getElementById('vouchersTable').getElementsByClassName('voucherCode')[1].innerText") ]
Imposta campo [ Browser Web::VAR txt ; $r ]

Start a video inside an interactive container on Win:

MBS( "WebView.RunJavaScript" ; "player"; "document.getElementById('Player').controls.play();" )

Redirect Window.Open to trigger a FileMaker Script:

Set Variable [ $r ; Value: MBS("WebView.RunJavaScript"; "web"; "window.open = function(url, name, features, replace) { location.href='fmp://$/MyDatabase.fmp12?script=NewWindow&param='+url; }") ]
// may not work for all platforms!

Query text of an element found by it's CSS class name:

MBS( "WebView.RunJavaScript"; WebViewerRef; "document.getElementsByClassName('topteaser_master')[0].innerText")

See also


WebView.RenderPDF   -   WebView.RunJavaScriptReturnTitle

Feedback: Report problem or ask question.




Links
MBS Realbasic PDF Plugins - Pfarrgemeinde Messdiener Nickenich