Method 1: Inserting JavaScript Into a Topic

If you want some JavaScript to work in a single topic in a project, you can insert the code directly into the topic.

How to Insert JavaScript Into a Topic

  1. From the Content Explorer, double-click the Attractions.htm topic. The topic opens in the XML Editor.
  2. Scroll down and add an empty paragraph at the bottom of the topic, with your cursor placed in it. If you don't want the script in its own empty paragraph, you can just place your cursor next to a block element (e.g., heading, paragraph, image).

    Note In some situations (depending on the script), the location of the script in the topic body might be more important. But in most cases, including this one, the exact location of the cursor in the body doesn't make much difference. You can insert the script somewhere else if you like (e.g., at the very top).

    If you are inserting a link to a script file (instead of inserting the actual code, which we are doing here), you can alternatively use the Internal Text Editor to place the script inside the <head> tags, which is often preferred over inserting the script in the body area; later, we will use this technique when inserting a script in a template page.

  3. Select the Insert ribbon, and near the right end of the ribbon click Script.
  4. From the Language drop-down, select text/javascript.
  5. Copy the JavaScript code provided and paste it in the Script Code field.
  6. Click OK. A small icon displays at the location where you inserted the script.

  7. Click Save the active file. to save your work.
  8. Build and view the All-About-Austin-HTML5 target.
  9. In the output, open the Attractions topic and scroll down. Notice the button in the lower-right labeled "Top." Click it to scroll to the top. If you open any other topic and scroll down, you will not see this button, because the script was added only to the Attractions topic.
  10. Let's delete the inserted script before continuing in this tutorial. So in the Attractions.htm topic in Flare Desktop, right-click the JavaScript icon, and delete it.
  11. Click Save the active file. to save your work.