Cross-References and Links

2 min read

Add Downloadable Files

To provide downloadable files in your content, you need to add external links pointing to those files on your server, and a script that turns external links into downloadable files.

Add Download Link

A download link is an external link with the role attribute set to download. Download links will not work without a script that turns them into downloadable files.

To add a download link in a topic:

  1. Select the topic or component in the Content Manager to open it in the Editor.

    Alternatively, you can Create a Topic and edit that.

  2. Position the cursor where the link is to be inserted.

    Tip

    Alternatively, highlight the text that you want to use as link label.

  3. Select the Insert tab in the Toolbar.

  4. Select Link and choose External link.

  5. Enter a Link label and Link target.

  6. Select Insert.

  7. Select the link in the Element Structure Menu and choose Go to element.

  8. Add the role attribute in the Element Attributes Panel and set its value to download.

  9. Select Save.

Convert Links into Downloadable Files

Download links will not work unless you add a script that turns them into downloadable files:

  1. Use a text editor or code editor for creating (or updating) the JavaScript file.

  2. Add the following script:

    // Use the text content of the link as filename rather than the last part of the URL
    const useTextAsFilename = true;
     
    $(document).ready(function () {    
        const links = document.querySelectorAll(".link.download");    
        links.forEach((link) => {        
            if (useTextAsFilename) {            
                const text = link.textContent.trim();            
                const safeName = text.replace(/[\/\\:*?"<>|]/g, "_");  
     
                 link.setAttribute("download", safeName);        
            } else {            
                link.setAttribute("download", "");        
            }    
        });
    });
  3. Save your JavaScript file making sure it has a .js filename extension.

  4. Upload Customized JavaScript