Some weeks ago, during christmas, I found this spanish article in tu función about how to get the Google PageRank of any website with PHP (he will be happy with the keywords of the link).
The fact is although I knew there would be a lot of cross-domain problems I told myself:
“hey! you have to convert that PHP code to javascript. You will attract lots of visitors for sure!”
¿What happed? Well, I wrote the code, then the code does the right request to Google and Google returns the Page Rank of the requested page, but… oh my dear! the returned string should be parsed and there is no possible way of reading it. I then tried and tried tons of things, but it is a matter of browser security (which I perfectly understand, and are perfectly reasonable), so nothing could be done (ohhhhhhhhhh).
Accessing cross-domain contents is not possible using only javascript. It does not matter if those contents are loaded on an iframe or even with AJAX (e.g: by using XMLHttpRequest or ActiveXObject(‘Microsoft.XMLHTTP’), depending on the browser).
The truth is that I’ve been researching a lot about cross-domain security, and I think I learnt a lot. Unfortunately the conclussion is very clear: never try to use javascript to integrate HTML contents of other domains in your own. It’s not going to work.
There were a couple of solutions, like using flash or even doing a PHP proxy, but that was not my objective.
Well, once arrived to this conclussio… in the following post I will give the source code, and an example for getting Google PageRank of any webpage using only javascript. Yes ladies and gentlemen, I can say “I got it”, but I let you know that you are not going to like the solution, although the PageRank number is shown
I’ve finally tried the source code on Opera/Safari/FF3/IE7 and it seems that the trick works in all of them (at least in my environments). Look at the following screenshot:

That said, and knowing it works on all those browsers, you’ll have to wait for tomorrow ;p
Español
21/01/2009 at 2:14 pm Permalink
Solo para que conste, con flash tampoco se puede hacer un request cross domain, el flash player tiene un póliza de seguridad, sin embargo existe una forma más elegante de pasar por el, el crossdomain.xml
21/01/2009 at 3:23 pm Permalink
Ala, a esperarnos hasta mañana…
22/01/2009 at 1:34 am Permalink
Hector, sobre Flash habia leido algo del crossdomain.xml, y el concepto final es que había una forma, aunque para ser sinceros, sólo lo he leido y no lo he probado por mi mismo, así que no se hasta que punto es o no cierto, ni bajo que condiciones funciona. También debo reconocer que en flash estoy bastante verde.
30/11/2011 at 9:17 am Permalink
just a redirection to PHP, not worth it’s visit.
14/04/2012 at 7:37 am Permalink
Será de probar el código para ver si funciona.