Alert when a UI page loads

Evan2
Kilo Guru

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

4 REPLIES 4

Beth11
Giga Guru

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);

Manish Vinayak1
Tera Guru

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");
});

Kunal Varkhede
Tera Guru

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,

 

larryhems
Kilo Explorer

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.