Adding Universal Scripts to Websites

Overview

If you want to add universal codes or scripts to your websites across all pages, you must modify the skin of your website or add the script to the page header. This article describes the process of adding a universal code on your website. 

 


 

Prerequisites

  • Access to the DNN server and Read and Write permissions to the file system
  • Administrator or SuperUser account.

 


 

Solution

Solution #1

  1. Open the Windows File Explorer.

  2. Navigate to the folder where your DNN site is installed, and open your skin folder at SiteRoot/Portals/_default/skins.

  3. Open one of the folders for a specific skin. This will depend on which skins you have installed for your site.

  4. Within the skin folder, open one of the .ascx files for your skin. The file you choose will depend on which pages you want to display the script on. For example, in the image below, the default skin, main.ascx, is located at SiteRoot/Portals/_default/Skins/Cavalier/. For portals using the Cavalier skin, the main.ascx file is commonly loaded on the many pages.

    Screen_Shot_2019-07-05_at_4.26.31_AM.png

  5. Using a text editor, edit the .ascx file and append your code to the bottom of the page.

    2_Append_Code_to_Skin.png

    <script type="text/javascript">
    console.log("my personal code");
    </script>
    Notes: The source code of the .ascx file will be different if you are modifying a file that is not main.ascx from the Cavalier skin. Also, the javascript snippet is just an example, you should replace it with the real script that you wish to load on your pages.
  6. Save the file.
  7. Restart the application. For example: Navigate to Persona Bar > Servers and click Restart Application.

  8. Browse to the site and hit on Ctrl + F5. (This clears the cache of the previous version of your page.)

 

Solution #2

You can add the script to the Page header for all the pages.

  1. Log in as an Administrator or SuperUser
  2. Go to Settings > Site Settings > Site Behavior
  3. Append the script in the HTML Page Header Tags section
  4. Click Save

    2020-05-26_1348.png

Back to Top


 

Testing

  1. Right-click on any page and select View Page Source.

  2. The added code is present when viewed in View Page Source.

  3. The script executes as intended. (This requires that your included script is functional.)

 

Back to Top

Comments

0 comments

Article is closed for comments.