Alert when a UI page loads
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2019 05:29 PM
Hi All,
We have a UI page and we want to get a alert when this UI page loads. For this I have tried to write a client script as below but its not working. Plz help.
function onLoad() {
//Call a UI Page to Display on load.You have to create the UI Page separately
var gDialog = new GlideDialogWindow('custom_survey_page'); // custom_survey_page is a UI page
gDialog.setTitle('This is survey response from client script');
gDialog.setSize(700,700);
gDialog.render();
}
Regards,
Evan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2019 05:36 PM
Unfortunately I don't have time at the moment to work up a full example, but this should help point you in the right direction.
Remember that your servicenow function availability in a UI page is going to be very limited. Try leveraging standard javascript in your client script instead:
window.onload = function(){
alert('I'm an on-load alert!');
};
You could also use:
document.addEventListener('DOMContentLoaded', function() {
alert("Ready!");
}, false);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2019 06:06 PM
Go with Beth's reply. It should work.
Another option would be using jQuery for the onload trigger in your UI Page Client Script:
$j( document ).ready(function() {
alert("Document Loaded");
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2019 06:33 PM
Use this script it gives alert when this UI page loads
addLoadEvent(loadMe);
function loadMe()
{
alert('Loading');
}
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2021 08:57 PM
document.ready() Vs. body onload()
The ready event occurs after the HTML document has been loaded, while the onload event occurs later, when all content (e.g. images) also has been loaded.
The purpose of the jQuery ready() event is that it should occur as early as possible after the document has loaded, so that we can immediately add functionalities or event handlers to the html elements without waiting for the entire page to load. We can have multiple document.ready() in a page but Body.Onload() event cannot.