The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to include a JavaScript library within the ServiceNow head tag?

wolfgangb
Giga Contributor

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?

1 ACCEPTED SOLUTION

ChrisBurks
Mega Sage

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


})();


topWindow.png


View solution in original post

7 REPLIES 7

Chuck Tomasi
ServiceNow Employee
ServiceNow Employee

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


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.


Hi Chuck,



Any ideas on that?



Thanks,


Wolfgang


No ideas at this time. Perhaps someone else in the community can jump in.