How to load the framework programmatically without errors?


Topic: How to load the framework programmatically without errors?

Juric asked 6 years ago

Hi,

for some reason, it would be helpfull, to laod all necessary scripts and css files programatically.

So I tried this code (which is in one file, which is referenced in the header of the document):

function addJsFile(_file){
    let _JsFile = document.createElement('script');
    _JsFile.src = _file;
    document.head.appendChild(_JsFile);
}

function addCssFile(_file){
    let _CssFile = document.createElement('link');
    _CssFile.href = _file;
    _CssFile.type = "text/css";
    _CssFile.rel = "stylesheet";
    document.head.appendChild(_CssFile );
}

function load_mdb_framework(){
    addJsFile("./approot/jquery/mdb_pro/js/jquery-3.3.1.min.js");
    addJsFile("./approot/jquery/mdb_pro/js/popper.min.js"); 
    addJsFile("./approot/jquery/mdb_pro/js/bootstrap.min.js");  
    addJsFile("./approot/jquery/mdb_pro/js/mdb.min.js");
    addCssFile("./approot/jquery/mdb_pro/css/bootstrap.min.css");
    addCssFile("./approot/jquery/mdb_pro/css/mdb.min.css");
}
load_mdb_framework();

If I run the page, I have some error messages in the console (IE and Chrrome) like: Unable to get property 'addEventListener' of undefined or null reference (mdb.min.js, Line: 1, Column: 204609)

Can you help with this or explain, why it doesn't work? Thanks


Bartłomiej Malanowski staff pro premium commented 6 years ago

Did you try to update your version of MDB to the most recent version?


Juric answered 6 years ago

Yes, I have the newest version, I suppose. 4.6.1 Cause we just updated it about a week ago


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.6.1
  • Device: Desktop
  • Browser: IE 11, Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No