views:

34

answers:

1

Hi!

I have a php page and the behavior is this:

  1. the page is opened
  2. user press on button and than a pop-up is opened
  3. in the pop-up page the user select a date and press ok
  4. the pop-up is closed and the main page is refreshed with the new data (this is not ajax)

I want that after the pop-up is closed , a loading message in the main page until the page finish to load. so i tried this but this is not working..

<script type="text/javascript">
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  document.getElementById("loading").style.display="none";
});

</script>

<body id="page" onload="addLoadEvent();">

<span id="loading">Loading Data..</span>

the pop-up:

   <script type="text/javascript">
   echo 'top.opener.location=\'page2.php?date='.$date2.'\';window.close();';
   echo '</script>'; 

i tried also this code:

window.onload=function() 
    {
        document.getElementById('loading').style.display='none';
    }
 <span id="loading">Loading Data..</span>

but now "loading date" is presented always. thank you!

A: 

Looks like you defined addLoadEvent() and never used it.

Edgar Bonet
the function is include in the `load()` function..
Ronny
The function is **defined** in `load`, but it is never **used**!
Edgar Bonet
you right. i edited the question.
Ronny
Now remove `onload="addLoadEvent();"` from your `<body>`. You already called `addLoadevent()` in the `<script>`.
Edgar Bonet
still having problems..the "loading data" is presented always.
Ronny
It should’t. Show the complete HTML page.
Edgar Bonet
i found the problem..thank you
Ronny