It is really up to you if you want to execute your function after load the whole page you can do it. if you use jquery u can create this block which will execute ur function just after your page load.
$(document).ready(function(){
// code will goes here
});
1
solved Loading of scripts