window.onload function works with alert