Execute a javascript function as last inside a page

This depends on the order in which you have registered them.

E.g:

$(document).ready( function() { alert("first"); });
$(document).ready( function() { alert("second"); });
$(document).ready( function() { alert("third"); });​

would alert "first" then "second" then "third"

So adding a <script> to the bottom of your page with an $(document).ready( yourfunction ); would suffice.


There are many ways to delay the execution of a script.

There is no way to programatically detect all of them.

For a reliable solution you would have to reverse engine the code of each page you care about, figure out what it is doing (and when) and write your delay script specifically for that page. (For a value of "reliable" equal to "until they change the page").


Theoretically you can do something like this:

// Form array of functions which sould be called with according order
$.readyArray = [function () { ... }, function () { ... }, function () { ... }, ...];

// just execute them in this order when onready event
$(document).ready(function() {
  for (var i = 0; i < $.readyArray.length; i++) {
    //apply, calls function in current context and pass arguments object
    $.readyArray[i].apply(this,[arguments]);
  }
});