0

i am trying to display a loading image when the page is loading.Here is my code.

<body onunload="doHourglass();" onbeforeunload="doHourglass();" onload="setTimeout('show()',2000);">
<div id="divWait" style="display:none" >
      <h1>wait...</h1>
  </div>

<div id="main" style="display:none">
<asp:Button ID="btnHidden" runat="server" OnClick="code behind handler"
<div/>
<script>
function doHourglass()
{
console.log("inside dohour glass");
var divwait=document.getElementById('divWait');
 var divmainpage=document.getElementById('main');
 divmainpage.style.zIndex="0";
 divwait.style.zIndex="1";
 divwait.style.display='inline';
divmainpage.style.display='none';
setTimeout("show()",2000);
}
function show()
{
console.log("inside show");
var divwait=document.getElementById('divWait');
 var divmainpage=document.getElementById('main');
 divmainpage.style.zIndex="1";
 divwait.style.zIndex="0";
 divwait.style.display='none';
divmainpage.style.display='inline';
}
</script>
</body>

Problem is, it is not working when the page is loading for the first time.when i checked using console.log() i see for the first time control is not going inside doHourGlass() function.but for button click event it is working perfectly.

Things i tried:checked this link on SO, but i am not putting static html.I am trying to get the id of an html element and then working on that element so i can not use that solution.

Edit:one way i found is to keep divwait visible and hide main division then show main div when the page loads.but this way i can only display static html.i want to be able to call a function when page is loading for first time.
what is happening?is there a way to achieve it?please guide me.

Community
  • 1
  • 1
shreesha
  • 1,811
  • 2
  • 21
  • 30

0 Answers0