views:

30

answers:

1

I have a script that runs on some pages. The problem is that I attach the script on the page load, but all links on the page make requests and change the contents from the response. (The url's hash changes)

I need a way to check when the "page" is finished loading to add my scripts.

The problem:

somesite.com/home (event load is fired)

*user clicks a link*

somesite.com/home#profile (event load isn't fired, the page is
                           already loaded, but the contents are
                           being changed through ajax calls)

How can I do that? I'm thinking on adding a watcher that will check the page all the time and call the corresponding script.

How can I check if the page is sending a request and execute something when the request ends? (I guess it's possible since Firebug does that)

A: 

You could use setInterval, and check every 500 ms for changes in the location hash:

var oldHash = '';
setInterval(function(){
   var newHash = location.hash;
   if(oldHash != newHash){
      oldHash = newHash;
      // do something
   }
}, 500);
Lekensteyn
I guess there is no other way... Thanks.
BrunoLM