HartleySan HartleySan - 5 months ago 20
Javascript Question

How does Google mask the real URLs of links on search results pages?

The following I tested on the latest versions of Chrome and Firefox, and IE11, and the results were the same.

If you do a Google search and then mouse over a link on the search results page, the link shown in the bottom-left corner of the browser window is not the same as the actual

of the

In all three browsers I tested this on, if you inspect the link in the element inspector though, you can easily see the real link (which is to
), and while the inspector is open, if you mouse over the link again, then you'll see the real URL link in the bottom-left corner of the browser window.

I have two questions regarding this behavior?

  1. While perhaps a bit naive to ask, why does Google do this?

  2. How does Google do this? Because I saw this behavior in Chrome, Firefox and IE11, I'm thinking that this is some JavaScript-controlled behavior (as opposed to some browser-controlled behavior), but I've never heard of this being possible in JavaScript. If it is possible in JavaScript, how do you do it?

Thank you.

Answer Source

Look at the initial markup:

<a onmousedown="return rwt(this,'','','','3','AFQjCNF8xnW_qOvuZURbtcZUvB6zhKtRQw','35cXyZwuoZY8hBY1VfDr8Q','0CEAQFjAC','','',event)"
   <em>How Do You Do It</em>? - Wikipedia, the free encyclopedia

Initially the href attribute shows the "real" URL. But when you click on the link, the rwt function changes the attribute value to


To answer your question: they use the onmousedown attribute to change the link's href attribute when you click on it. Barmar points out why they do it.