The Now Platform® Washington DC release is live. Watch now!
‎02-01-2017 04:36 AM
I understand that ui scripts that are marked as global are loaded with every page that ServiceNow loads. These pages are running within an iframe.
How can I include a JavaScript library within the global head HTML tag for each page?
Solved! Go to Solution.
‎02-03-2017 08:28 AM
If you place something like below in a UI script and make that global should work.
(function(){
var top = getTopWindow().window.document.querySelector('head'); // reach out to the parent window and get the head element
var script = document.createElement('script'); //create a new script element
script.src = 'path/to/js/library'; //sets the src attribute
script.type = 'text/javascript'; //sets the type attribute
top.appendChild(script); // appends the newly created script element at the end of the top window head element
})();
‎02-01-2017 05:09 AM
Hi Wolfgang,
Can you clarify what it is you are trying to do? What requirement is driving you to the solution that you need a JS library loaded on every page?
Thanks
‎02-01-2017 05:27 AM
Well the use case is pretty simple, I would like to include a monitoring framework such as Dynatrace into my ServiceNow instance. It works ok with a global ui script, but it is stuck in the page iFrame which is not the perfect solution.
‎02-02-2017 11:16 PM
Hi Chuck,
Any ideas on that?
Thanks,
Wolfgang
‎02-03-2017 05:52 AM
No ideas at this time. Perhaps someone else in the community can jump in.