- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 09:11 AM
Hi ChrisB,
I tried to use the function but I get 'Uncaught ReferenceError: getTopWindow is not defined' error. Am I doing something wrong? I am on Kingston patch 4.
var top = getTopWindow().window.document.querySelector('head'); // reach out to the parent window and get the head element
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2018 12:42 PM
I tested on Kingston patch 6 and it works. I don't have a patch 4 environment to test on.
Aside from that where exactly are you trying to use the this function?