Referencing Custom JavaScript and CSS Files

Note: This section applies to classic forms. For CSS and Javascript in the Form Designer, see this section.

In addition to writing JavaScript and CSS on the CSS and JavaScript page, you can also include references to other JavaScript and CSS files. Including external JavaScript and CSS files can make it easier to maintain your code.

You can reference any JavaScript or CSS file hosted on the web.

To reference a JavaScript file

  1. Enter the following code in the JavaScript section of the CSS and JavaScript page:
  2. $(document).ready(function () {
        $.getScript('ScriptURL/scriptname.js', function() {
            //code goes here
        });
    });
    
  3. Replace ScriptURL/scriptname.js with the URL of the JavaScript file.
  4. Replace code goes here with your code that references the external JavaScript file.

    Note: Placing your code in this function ensures that it will wait for the external script to load before running.

  5. Click Save.

To reference a CSS file

  1. Enter the following code in the JavaScript section of the CSS and JavaScript page:
  2. $(document).ready(function () {
        $('head').append('<link rel="stylesheet" href="server/CSSFileName.css" type="text/css" />'); 
    }); 
    
  3. Replace server/CSSFileName.css with the URL of the CSS file.
  4. Click Save.