IncludeJavascriptAPI - how to add Script attributes

Hi, I have a question regarding the IncludeJavascriptAPI and <Script> attributes.

We already use the API to successfully include javascript commands on our application pages. We add the javascript code, and the API automatically wraps the commands we add with the <Script> element, so we do not include the <Script> ourselves.

We now have a requirement where the javascript we want to add has <Script> attributes, but I can't see any way of doing this using IncludeJavascriptAPI. If I remove the <Script> tag and just add the attributes i need it adds as javascript code between the <Script>.

e.g. I need to add something like <script attribute1="value1" attribute2="value2></script>

API will create

<script type="text/javascript" charset="UTF-8">

    <script attribute1="value1" attribute2="value2></script>

</script>.

if I remove the <script> , i get (unsurprisingly)

<script type="text/javascript" charset="UTF-8"> 

  attribute1="value1" attribute2="value2

</script>.

So basically the question is, can we add Script attributes using the IncludeJavascriptAPI?

Any suggestions would be appreciated.

Regards

Neil



I have solved one part of my problem.

I need to include a src="url" and by just adding the url text (conforming to the isURL) it will include it as the src attribute in the <Script>

However I do still need to work out if i can add another attribute - specifically ' crossorigin="anonymous" '

Solution

Whilst looking at another thread, regarding the use of GoogleTagmanager, I realised i could use a similar process to add the scripts in need by using a js function - I can do this with my existing IncludeJavascript API screens

e.g. (function() {

  var po = document.createElement("script");

  po.type = "text/javascript";

  po.charset = "utf-8";

  po.src = "https://mysrc.js";

  po.setAttribute("crossorigin","anonymous");

  var s = document.getElementsByTagName("script")[0];

    s.parentNode.insertBefore(po, s);

  })();

Of course there may be other ways to achieve this ;)
Solution