Custom script tag in page

Hi, I have a question: how do we add script tags to the page that we create? How to achieve this? From earlier forum queries, I somehow got an idea that either custom widgets or javascript snippet could be used. Which is a better approach to achieve this?  Thanks in advance Kamala
2 answers

See This is the same advice as Ockert’s advice, but with some extra information and in the Mendix docs. There you will read that indeed it is the Mendix preferred way to not load external scripts. And about the best practices using javascript actions.


You can add the script tags to $PROJ/theme/index.html, mendix has a tendency to do some wonky stuff and sometimes redirects to index1.html, index2.html,… indexN.html, so just copy index.html into index${seq 0 1 1024}.html to take care of that.

If you want per page script tags, you can use an html snippet that puts the script tag, something like this will insert and execute / load then execute


    var s = document.createElement("script");
    s.type = "text/javascript";
    s.src = "http://scriptlocation/das.js";

Todo: Check if already present

Additionally these script tags can be set to point to a web service exposed on the local Mendix runtime serving up concatenated Script entity value fields so you can configure it at runtime, ensure you have an additional webservice exposed to manipulate the config via rest as buggy JS served up and executed can crash the client

Or you can write a widget