CRecordWebAddScript

The message CRecordWebAddScript adds a JavaScript to the website.

The message is part of the RemoteSkin Web API.
The API is located in the plugin NY_RemoteSkinWebProtocolAPI.

{
  "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.

// Example: Load script from JAR resources
String js = 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

The RemoteSkin target address is also required.

public void addScript(@NotNull final CTargetAddress aRemoteSkinAddress,
                      @NotNull final String aId,
                      @Nullable final String aContent,
                      @Nullable final String aSource) throws CException
{
    // Envelope
    final CEnvelope env = CEnvelope.forSingleTarget(mRemoteSkinAddress);

    // Record
    final CRecord record = CRecordWebAddScript.create();
    CRecordWebAddScript.setId(record,
                              aId);
    if (aContent != null)
    {
        CRecordWebAddScript.setContent(record,
                                       aContent);
    }
    if (aSource != null)
    {
        CRecordWebAddScript.setSrc(record,
                                   aSource);
    }

    // send message
    sendNotification(env,
                     record);
}

See also: