WebView.AddUserScript
---------------------

Adds a user script.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [WebView](component_WebView.md) | [9.5](newinversion95.md) | ✅ Yes | ❌ No | ❌ No | ❌ No | ✅ Yes |

MBS( "WebView.AddUserScript"; WebViewerRef; Source; injectionTime; forMainFrameOnly ) 

**MBS**( **"WebView.AddUserScript";** /\* Adds a user script. \*/  
**$WebViewerRef**; /\* Either the Web Viewer Object Name or the Web Viewer ID as returned by "[WebView.FindByName](WebViewFindByName.md)" function. \*/   
**$Source**; /\* The source code. \*/   
**$injectionTime**; /\* The time when the script should be injected into the webpage.  
AtDocumentStart: Inject the script after the document element is created, but before any other content is loaded.  
AtDocumentEnd: Inject the script after the document finishes loading, but before other subresources finish loading.e.g. "AtDocumentEnd" \*/   
**$forMainFrameOnly**) /\* A Boolean value indicating whether the script should be injected only into the main frame (true) or into all frames (false).e.g. 1 \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| WebViewerRef | Either the Web Viewer Object Name or the Web Viewer ID as returned by "[WebView.FindByName](WebViewFindByName.md)" function. |  |
| Source | The source code. |  |
| injectionTime | The time when the script should be injected into the webpage.   AtDocumentStart: Inject the script after the document element is created, but before any other content is loaded.   AtDocumentEnd: Inject the script after the document finishes loading, but before other subresources finish loading. | "AtDocumentEnd" |
| forMainFrameOnly | A Boolean value indicating whether the script should be injected only into the main frame (true) or into all frames (false). | 1 |

### Result

Returns OK or error.

### Description

Adds a user script.  
Only for FileMaker 16 and newer in WebKit 2.x web viewer on Mac and iOS.  
### Examples

Add a test script:

 MBS ( "Webview.AddUserScript"; "web"; "alert('Hello');"; "AtDocumentEnd"; 1 )  
### See also

- [WebView.FindByName](WebViewFindByName.md)
- [WebView.UserScripts](WebViewUserScripts.md)

### Release notes

- **Version 10.0**
    - Fixed memory leak in [WebView.AddUserScript](https://www.mbsplugins.eu/WebViewAddUserScript.shtml) function.
- **Version 9.5**
    - Added [Webview.AddUserScript](http://www.mbsplugins.eu/WebviewAddUserScript.shtml), [Webview.UserScripts](http://www.mbsplugins.eu/WebviewUserScripts.shtml) and [Webview.RemoveAllUserScripts](http://www.mbsplugins.eu/WebviewRemoveAllUserScripts.shtml) functions.

### Blog Entries

- [MBS FileMaker Plugin, version 9.6pr3](https://www.mbsplugins.de/archive/2019-12-17/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)
- [New functions of the MBS Plugin Version 9.5](https://www.mbsplugins.de/archive/2019-11-21/New_functions_of_the_MBS_Plugi/monkeybreadsoftware_blog_filemaker)
- [Neues MBS FileMaker Plugin 9.5](https://www.mbsplugins.de/archive/2019-11-12/Neues_MBS_FileMaker_Plugin_95/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 9.5 - More than 5900 Functions In One Plugin](https://www.mbsplugins.de/archive/2019-11-12/MBS_FileMaker_Plugin_95_-_More/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.5pr8](https://www.mbsplugins.de/archive/2019-11-08/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 8th November 2019 , last changed 5th January 2020

  
[WebView.AddScriptMessageHandler](WebViewAddScriptMessageHandler.md) - [WebView.AllCookies](WebViewAllCookies.md)

[HTML Version](WebviewAddUserScript.shtml)