Custom script tag in page

0
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
asked
2 answers
2

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

 

$(document).ready(function() 
{
    var s = document.createElement("script");
    s.type = "text/javascript";
    s.src = "http://scriptlocation/das.js";
    $("head").append(s);
});

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

answered
2

See https://docs.mendix.com/howto/extensibility/best-practices-javascript-actions#2-2-6-using-external-dependencies-in-the-browser. 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.

answered