How to autoload javascript in extension when the application starts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kamolpech
    Junior Member
    • Oct 2018
    • 17

    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
  • yuri
    Member
    • Mar 2014
    • 8440

    #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.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • kamolpech
      Junior Member
      • Oct 2018
      • 17

      #3
      yurikuzn, thanks for the answer.

      Comment

      • telecastg
        Active Community Member
        • Jun 2018
        • 907

        #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...