When, for example, tracking conversions on your site with Google Analytics, you may be required to execute a small Google-provided script on certain actions.
If you are using Blazor or AngularJS rendering, we know that you have a browser at the user's end.
If you assign an existing js-function name (that you provide with a js file and include in component or global scripts) in this format:
FunctionName(argument)
The client (both Blazor and AngularJS) will detect and call this pre-existing function by assigning a special string variable named vClientScriptExecute:
vClientScriptExecute:='MDrivenClientScriptExecute("Some string arg")' -- the argument is double-quoted
We will try to match it with: thescriptref.match(/^(\w+)\s*\(\s*"([^"]*)"\s*\)$/); - so you must include a param in double quotes
Once the vClientScriptExecute has a new value, the client will try to call it.
If you need more arguments, you need to encode them in the one argument available.
How to test:
- In EXT_Scripts/AppWideAngularScriptIncludes.htm put this line: <script src='EXT_Scripts/MyThings.js'></script>
- Create a new file in EXT_Scripts/MyThings.js
- In MyThings.js, add: function ThisIsMyFunction(param1){window.alert('This is my function alert('+param1+')')}
- In viewModel, add an Action with the expression: vClientScriptExecute:='ThisIsMyFunction("hello man")'
Expected outcome: When you click the action, an alert is shown like this:
