Shatu
Shatu

Reputation: 1839

Modifying Google Search Results Page

I have written a greasemonkey script which will do GM_xmlhttpRequest to the next 2 pages of the google results page.. i.e. if my current page is 1 then my script will do GM_xmlhttpRequest to page no 2 and 3..

Now my script will extract out all the urls from these 3 pages and will reorder them

For that I have done:

unsafeWindow.addEventListener('load',Reorder,true);

function Reorder()
{
alert("onload fired")
..........
..........
// some code overhere to collect all the urls into an array
// and to reorder the urls in the array

Now I inject these urls into my reference pages i.e. I keep a reference to the nodes where I am supposed to append these urls as childNodes.. and along with that I modify the links to page no. 2 and 3(at the bottom of results page) so that now they'll point to my these newly dynamically generated pages. For that I modify the onclick attribute of these links that'll open a new window in the current window itself and will write the modified responseXML object to the newly created window.

Now everything is working awesome i.e. url extraction, reordering, creating new window, writing the responseXML object ..

But the problem is that when my these modified links are clicked and my newly generated window replaces the parent window it doesn't give the alert of "onload fired" ...infact it doesn't stop loading i.e. it displays the desired content but is never fully loaded since status bar doesn't shows "done" in fact it shows "waiting for clients1.google.com"...

So does anyone knows what exactly is going wrong over here.. is it due to some script running on google search page that is somehow synchronised with the contents of the page...

Basically for those who do not know how greasemonkey will work.....my code is just removing all the anchor tags that contain url and inserting similar anchor tags with different urls...the question in nutshell is that i am just making a new window and doing document.write(this newly created html page)...and other than the urls I am not changing anything.... so basically are the scripts somehow synchronized with the urls present on the page or does it really matter to the scripts what data is contained within as long as the body contains the same DOM tree.

Please people whatever you know or have idea about it.. please tell me...

i need to finish this thing quickly..

Upvotes: 1

Views: 392

Answers (1)

casablanca
casablanca

Reputation: 70701

When you use document.write to write content into a new page, you need to use document.close() to tell the browser that you're done - until then, the browser thinks there is more content to come and continues to display the loading icon.

Upvotes: 1

Related Questions