Onload in the widget

Adil JEBLI
Mega Expert

Hi Everyone,

Can anyone tel me how i can use onload to call another function.

example in HTML : ( <body onload="someFunction()"> ...</body>)

Thank you

5 REPLIES 5

mayurkamble
Kilo Guru

Hi Adil,



Use ng-init="functionName()" this function will execute when the widget or the variable you specified it withing loads.



Let me know if it works.




Regards,


Mayur


Hi Mayur,


thanks for your answer.
I have already use it but it does not work 😕



this is what i did:



html


<div ng-init="test()">


 


</div>



client script:


function test(){


alert('hhh');


}


Mr_X
Mega Guru

Hi Jebli,

Please use the below code.

HTML:

<div ng-init="c.onload()">

</div>

 

Client script:

function() {
var c = this;
c.onload = function(){
alert("onload");
}
}

 

Let me know if you need any assistance.

 

Thanks

Naveen K

I am having a related issue, however, mine is more specific to the widget not being populated with the script is run, rather it shows up at the bottom of the parent page.

 

https://community.servicenow.com/community?id=community_question&sys_id=f1ff1814db00e8549e691ea6689619aa