Friday, November 18, 2011

Google's onmousedown link trickery

So you do a Google search. You find something interesting, but instead of clicking on it perhaps you just want to copy the link. Say you want to IM it to a friend or paste it into a malicious site search service. So you right-click on the link and "Copy Link Location" or whatever it is for you people on Chrome/IE/Safari/Opera/RockMelt(loljk). Then you paste it into your destination, but what you get looks like this:

Obviously Google's using some redirection trickery for some kind of internal purpose. But when you hover your mouse over the link, the url that shows up at the bottom of the window is the normal, short, non-Google link! And that hover-over url never lies, right? How is this happening?

Well, the good news is that technically the hover-over url isn't lying. It is indeed the correct url at that moment. But try right-clicking on the link, and before you do anything else, notice the hover-over url again*. It's changed! It seems Google is using some Javascript tricks (like an onmousedown event) to show us the expected url at first, then change it at the last second.

Sneaky? Maybe.
Annoying? Definitely.
Clever? Absolutely.

*A note in case you try this yourself: this only seems to happen on like 1/4 of the links on a typical page. And there's no way to predict which ones it will affect.

1 comment:

  1. Great find! And I always thought how Google did that...