decorative banner

Editing an existing JavaScript


    You can use the JavaScript Editor to edit existing JavaScripts.

To edit an existing JavaScript:

  1. To open the JavaScript Editor, do one of the following:
    • Double-click the JavaScript icon in the document window.
    • Select the JavaScript icon in the document window, and then click the Edit button in the Inspector.
  2. If the icons on the toolbar in the JavaScript Editor are inactive, choose a script name from the Select Script menu on the JavaScript Editor toolbar. Alternatively, you can create a new script by clicking the Create Script Create Script button  button.
  3. Click the Events tab of the JavaScript Inspector to see the objects that can have events attached and the events they support. To add an event to your script, select the event in the Inspector, and then enter the event code in the Event Code text box.
  4. Create event definitions by entering event codes in the Event Code text box.
    Create event definitions by entering event codes in the Event Code text box.
  5. Click the Objects tab of the JavaScript Inspector to display the complete inventory of JavaScript objects. To add an object to your script, drag it from the Objects tab to the JavaScript Editor window.
  6. Tip iconClick a function declaration in the Functions list in the Script tab of the JavaScript Inspector window to navigate directly to that location in the script.

  7. Close the JavaScript Editor to save your work.
  8. Do one of the following to open your Web page in the browser you selected for previewing and testing in the Preferences dialog box:
    • Choose File > Preview In > Default Browser.
    • Click the Show in Browser button Show in Browser button in the toolbar on the toolbar.

    Note: In Mac OS, you cannot preview the effects of a JavaScript.

    The following sample JavaScript code shows how to use a simple JavaScript to display the time and date obtained from the viewer's operating system.

    JavaScript sample code and result
    JavaScript sample code and result
    • The document.write() method on the "Your Local Time" line writes an H1-formatted text string from the document to the screen of the browser.
    • The new Date() method creates a new date object containing the long version of the current date from the viewer's operating system. This object is assigned to currtime.
    • The last line is output to the browser's screen using a document.write() method, with the embedded currtime variable set to the current time and date.