Announcement

Collapse
No announcement yet.

How to autoload javascript in extension when the application starts

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to autoload javascript in extension when the application starts

    I create new extension and installed.
    I want the Application autoload javascript in extension when the application starts.
    How Develop?

    Thank,
    I'm not good english

  • #2
    There is a way to include your js file into main HTML.

    Create custom/Espo/Custom/Resources/metadata/app/client.json

    Code:
    {
       "scriptList": [
           "__APPEND__",
          "path/to/your/js/file.js"
       ],
       "developerModeScriptList": [
           "__APPEND__",
          "path/to/your/js/file.js"
       ]
    }
    Last edited by tarasm; 02-15-2022, 12:20 PM.

    Comment


    • #3
      yurikuzn, thanks for the answer.

      Comment


      • #4
        Tried the code above but my IDE threw a JSON formatting error: "scriptList" and "developerModeScriptList" are arrays, not object, thus the correct code should read:
        Code:
         {    
        "scriptList": [B][[/B]        
        "__APPEND__"      
        "path/to/your/js/file.js"    [B]][/B],
        
        "developerModeScriptList": [B][[/B]      
         "__APPEND__"      
        "path/to/your/js/file.js"    [B]][/B]
        }
        I also found a way to use this method to also incorporate custom CSS application wide by including the following code inside file "path/to/your/js/file.js"

        Code:
        $(document).ready(function(){
            $("head").append("<link>");
            var css = $("head").children(":last");
            css.attr({
                rel: "stylesheet",
                type: "text/css",
                href: "path/to/your/css/file.css"
            });
        });
        Last edited by telecastg; 04-11-2019, 06:20 PM.

        Comment

        Working...
        X