Get Google PageRank using only javascript (II)

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.

Trackback URL

, ,

  1. Abhinav Singh
    22/01/2009 at 8:21 am Permalink

    Nice but do you know it’s kind of illegal to get PR information like this?

  2. Pau Sanchez
    22/01/2009 at 8:54 am Permalink

    Really? Uhm… I didn’t know it was illegal.
    Could you provide a link from Google for reading more about this?

  3. Felipe
    25/01/2009 at 12:01 am Permalink

    Hola,
    Este script es un trabajo fenomenal. Me parece increíble que puedan hacerse estas cosas con javascript. En mi caso, el único problema es que me aparece el iframe delante del PageRank en Internet Explorer. En Firexfox funciona perfectamente. ¿Habrá alguna manera de esconder el iframe en el Explorer?

    Saludos y enhorabuena por tu trabajo.

  4. Pau Sanchez
    25/01/2009 at 5:00 am Permalink

    El caso es que yo lo he probado en FF3, Opera, Safari 3.1 en Windows, y IE7. Y he adaptado un poco la posición de la cadena devuelta por Google según el navegador para que saliera bien en todos ellos. Obviamente era posible y probable que según la configuración del ordenador de cada uno no salga bien.

    Si le echas un vistazo al código HTML de la demo (en este enlace), verás el siguiente fragmento de código:

    var topadd = 0, leftadd = 0;
    if ($.browser.msie) { topadd = 2; leftadd = 12; }
    else if ($.browser.mozilla) { topadd = 0; leftadd = 7; }
    else if ($.browser.opera) { topadd = -3; leftadd = 4; }
    else if ($.browser.safari) { topadd = 0; leftadd = 8; }

    Básicamente el código de arriba es para saber cuanto tiene que desplazar el iframe donde sale el PageRank para que salga perfectamente, según cada navegador. Puedes tratar de cambiar el topadd y el leftadd para el IE hasta que se vea bien, o si se te ocurre alguna otra forma de hacerlo, bienvenida sea, porque esta, todo sea dicho, es un poco chapuza 😉

    Un saludo y gracias por el comentario.

  5. Bronco
    04/04/2009 at 5:40 pm Permalink

    hey thx a lot for this solution!!! I think i will integrate it in my site! until today I didn’t know a reliable solution for getting the actual PR of websites. This is for the most webmaster a really important information. (not for all 🙂 ) . it’s only for me an indicator not more. hey and for those who say it’s illegal ,.. are you stupid robots without brain? do you really think everything google does was right? brave sheep do your job and eat gras and don’t disturb us anymore.

    again thx for this great chance to struggle the force of google and his approach don’t be evil.

    bronco.

  6. Kelvin72
    22/10/2009 at 1:22 pm Permalink

    And it also helps these young people understand some of the ways they might improve their community. ,

  7. Mark63
    22/10/2009 at 1:28 pm Permalink

    Mass Effect and a simple game like pong or snake, but they are all games. ,

  8. Murat
    10/05/2010 at 5:52 pm Permalink

    Super script. Many thanks . The iframe movement method is very intelligence.

  9. Jose
    12/06/2010 at 8:37 am Permalink

    Hola Pau.

    No es ninguna tonteria.
    Si estás haciendo una aplicación en php, que va a chequear un montón de veces el PR de varias páginas, lo último que deseamos es que G banee la IP del servidor que lanza la consulta.
    Por tanto, haciendo el check con JS, lo que hacemos es pasarle el marrón al cliente, y la IP del servidor donde tenemos la app alojada queda limpia a los ojos de G.
    ¡Muchas gracias por tu contribución!

  10. Naeem Soomro
    31/07/2012 at 7:41 pm Permalink

    yes that is very nice i liked it
    thanks for shariong scripts with us this way we can enhance our website