On the previous postr I explained that doing cross-domain requests has a LOT of problems, and even with those problems today I was going to post how to get Google PageRank using only javascript
The thing is you cannot get the response once you do a cross-domain request (unless you use some tricks like a PHP proxy, …), so the code I developed does not know which is the PageRank obtained, however it can show the PageRank number in the right position, and that’s exactly what my script does.
Following there is an iframe where you can set whatever web-page you want, and it will show it’s pagerank (if any). I promise it only uses javascript.
Check this demo in a new window
What the script does is compute a set of checksums of the webpage given, and then update some fields in a form and send it to Google using GET method; after that the result is loaded in an iframe. The thing is the iframe could not be manipulated (even read), even if you do the request using typical ajax methods, it won’t work either.
The hack, trick, or whatever you want to call it, is that the PageRank appears just after a predefined string (“Rank_1:1:”), so what the script does is just estimate which is the position where the PageRank number should appear, and then move the iframe so the PageRank is the only number shown.
I know doing this in javascript is very… in fact I don’t know the exact English word I have to use here, but let’s say it is not a nice solution.
Following there is the script that computes the checksums and creates the form for querying Google getpagerank.js. You can also check pagerank.html to take a look on how the script is integrated in a webpage.
Finally, if you want to embed the webpage on your blog, or whatever, here it is a method to do so:
¿What do you think? ¿is it good? ¿is it crap?
On the next couple of days I will explain how to do cross-domain requests using javascript and send information from one server to another.