The message adds a JavaScript to the website.
{ "id": "ebbe16ee-3f96-4068-ae8f-17cfd63f7c63", "name": "WEB_ADD_SCRIPT", "description": "Add a script.", "slots": [ { "key": "1", "name": "ID ", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "The script ID." }, { "key": "2", "name": "CONTENT ", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "Optional: The content of the script." }, { "key": "3", "name": "SRC ", "direction": "REQUEST", "mandatory": "true", "type": "STRING", "description": "Optional: The source url of the script." } ] }
Arguments
-
ID : The ID of the script ensures that it can be removed when it is no longer needed. -
CONTENT : Either: the content of a Javascript file -
SRC : Or: the path to a Javascript file
Usage with the helper class CWebApi
The easiest way is to call the corresponding method in the CWebApi class. The use of the class is described there.
// 00401_graph.js is located in a jar file loaded on another node Stringjs = CUtilJson.loadJson(getClass(), "/html/00401_graph.js") mWebApi.addScript("my_element_id" ,js ,null );
or
mWebApi.addScript(ID_SCRIPT2 ,null ,"https://d3js.org/d3.v7.min.js" );
Usage as message
public void addScript(@NotNull final StringaId , @Nullable final StringaContent , @Nullable final StringaSource ) throws CException { final CEnvelope env = CEnvelope.forSingleTarget(mRemoteSkinAddress); final CRecord record = CRecordWebAddScript.create(); CRecordWebAddScript.setId(record,aId ); if (aContent != null) { CRecordWebAddScript.setContent(record,aContent ); } if (aSource != null) { CRecordWebAddScript.setSrc(record,aSource ); } mTarget.sendNotification(env, record); }