0

Hello I have an aspx document, at the bottom of the page I have this code:

<script language="javascript" type="text/javascript">
      window.onload = migrate();
</script>

It works well, but it does a flickering in the page. The flickering is because I use a translation system... But if I put:

   <script language="javascript" type="text/javascript">
     window.onload = function () {
            migrate();
        }
    </script>

The flickering dissapear.

What is the difference?

Thanks!

Alex
  • 9,911
  • 5
  • 33
  • 52
Za7pi
  • 1,338
  • 7
  • 22
  • 33
  • 1
    the first one should be `window.onload = migrate;` – Arun P Johny Apr 10 '14 at 12:17
  • @^ "window.onload = migrate;" is similar to what question owner wrote in 2nd block. Perhaps, he wants to know the difference between 1st and 2nd block what would happen. – vivek_nk Apr 10 '14 at 12:28

1 Answers1

3

In the first code snippet, you are calling the migrate() function and assigning it the value returned from window.onload. (Assuming migrate() returns a function object).

In the second code snippet, you are defining the onload function which in turn will call the migrate() method.

Aryan Beezadhur
  • 4,503
  • 4
  • 21
  • 42
vivek_nk
  • 1,590
  • 16
  • 27
  • 1
    just to further explain things: in the first block you are defining that the `onload` event executes what `migrate()` returns (because of the paranthesis). If you want to run `migrate` as a function, set `window.onload = migrate;` – Alex Apr 10 '14 at 12:21
  • Is it logic to asign something to onload of window? – Za7pi Apr 10 '14 at 13:49
  • It is. window.onload=migrate; => when window loads this method will be called and the argument passed will be an Event object (load event). Also another way of this is .. – vivek_nk Apr 10 '14 at 13:57
  • You can see the comparison of them here (there is few differences, yes). - http://stackoverflow.com/questions/191157/window-onload-vs-body-onload – vivek_nk Apr 10 '14 at 14:00