Code in external files

You can reuse code by copying it into another file or by referring to the code in a separate file through the SRC attribute for the SCRIPT element.

StepsTo get code from a file and insert it in a Web Target Script editor:

  1. Select Insert From File from the pop-up menu. The code appears in the script editor, and there is no further connection with the original file.

Scripts in HTML documents can be stored in external files, rather than in the HTML document. When the browser sees an SRC reference in a SCRIPT tag, it requests the script file from the server.

StepsTo put a script saved in the page into an external file:

  1. Right-click in the integrated Script editor and choose Save As External Script from the pop-up menu.

  2. In the Save dialog, you can include the external file in the target by saving the file in the local directory for the Web target.

StepsTo associate the script with code in an existing external file:

  1. Right-click in the integrated Script editor and choose New Script. Choose Client for the type of script.

  2. Switch to Source view and add an SRC attribute to the SCRIPT element.

    For the value of the SRC attribute, you can assign:

The HTML editor recognizes the reference to the external file and displays the code in the integrated Script editor (when the script object is selected in the first drop-down list) as if it were part of the HTML document. The icon next to the object name in the drop-down list displays an additional image (of a paper sheet with a folded-back corner) to indicate that the script is saved separately.

To reference a server script that is stored in a separate file, you need to use the PSIMPORT tag. For more information about the PSIMPORT tag, see the Web and JSP Target Reference.