简体   繁体   中英

pageLoad function in master page and content page

I have a pageLoad js function in master page, and another one inside content page.

Does the first one (in master page) prevent the second one (in content page) from firing ?

It's the other way round. The one on the Content Page will be fired first. To know if one is messing with the other, simply debug it on Firebug or even on Visual Studio.

You can use the jQuery syntax to chain functions to run on page load in both Master and Child pages like this:

  $().ready(function() {
    // Do stuff
  }

Contents will be execute in the order that the appear on the page, from top to bottom.

You could force items to be run in a specific order with a construct like this in your MasterPage:

<script>
  $().ready(function() {
    // Do MasterPage stuff
    if (onChildPageLoad) onChildPageLoad();
  });
</script>

and in the child page place a script block like this:

<script>
  var onChildPageLoad = function() {
    // Do childpage stuff
  }
</script>

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