Besides all the embedded JavaScript that Docxpresso integrates out of the box it is also possible to load custom JavaScript to further enhance Docxpresso functionality and/or adapt it to specific needs.
There are several ways to load additional JavaScript to the Docxpresso end users interfaces:
- From the backoffice template edition interface as:
- Code that is stored together with the template settings
- As a link to an external .js file
- As an option parameter passed within the URL query
WARNING: standard SaaS instances required to be approved to include additional JavaScript. This is to avoid the possibility to spread malware through the Docxpresso interfaces.
In the following we elaborate on these options.
Template settings: loading custom JavaScript
Within the Docxpresso backoffice interface one may include JavaScript as follows.
By clicking on the > button located in the top menu:
If we then click on the “Custom JavaScript code” menu entry the following pop up is launched:
As you can see from the above screenshot it is possible to instruct the Docxpresso end user interface to load:
- The JavaScript code form an “External JS” file (from https://www.mydomain.com/js/external.js in this case).
- The code directly inserted in the “Custom JS” text box provided in the interface. In this case we have just included a simple alert to illustrate the functionality.
Like the JavaScript code may depend on the different Docxpresso interface, i.e. interactive document or web form, Docxpresso provides a globally defined variable “dxoInterface” that may take the values document or form so the developer can further customize his JS code.
Loading JavaScript from URL options
Whenever constructing a link to allow external users to access a Docxpresso interface one may include in the options parameter a “externalJs” property pointing to the external JavaScript that we wish to be loaded.
This method allows for maximum flexibility because it allows to further customize the code for predefined users.
The simplest possible to load dynamically these JS files is by the use of the Docxpresso SDK by first defining a data array:
$data = array("template" => 46, "responseExternalJS" => "https://www.mydomain.com/js/external.js")
(where the template id has been set to 46 as an example) and calling the SDK previewDocument method with $data as only parameter: previewDocument($data).