How to detect that a new google instant page has been shown?

256 Views Asked by At

I'm working on a browser extension that needs to make a call when a new google instant page is served and then modify the results (think SEOQuake).

Issue: If a user pastes a link directly into the url field and presses enter, a new page load will happen and my extension will run. However with google instant, although the url changes as you type the queries, you're technically still on the same page, so the extension fails to run.

I looked at SEOQuake's code and this seems to be how they solve the problem:

document.body.addEventListener("DOMNodeInserted", sq_bindAsEventListener(this, function(event) { //

It's a great solution however it isn't ideal for me because as far as I know, DomNodeInserted isn't supported by IE below version 9. (surprise!)

I'm bundling jQuery along with the app so I have access to all jQuery functions. I was thinking about using .keypress() and simply wait until there's been no input for a second - if it's google instant, I'll know for a fact the page has changed.

Another thought I had is to monitor if the URL has been changed; I can't seem to find any jquery or javascript functions that keep track if the url's been changed.

What's the best way to know that a google instant search has been performed?

2

There are 2 best solutions below

0
On

A crude solution: use setInterval() and check if the window.top's location changes (that means a new query has been performed).

0
On

Listening to hashchange might be the way to go.

Older IE ( <8 ??) won't give you the event, so you may still need the timer there. All this trouble in case instant is available on IE7, of course, which I doubt is the case, anyway.