Quantcast
Channel: javascript – Codigo Manso
Viewing all articles
Browse latest Browse all 10

Get Google PageRank using only javascript (I)

$
0
0

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:

Screenshot sobre como obtener el Page Rank de Google con javascript

That said, and knowing it works on all those browsers, you’ll have to wait for tomorrow ;p


Viewing all articles
Browse latest Browse all 10

Trending Articles