简体   繁体   中英

Difference between window.onload = function () vs window.onload=

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM