How does Google mask real link urls on search results pages?

The next thing I tested in the latest versions of Chrome and Firefox, and IE11, and the results were the same.

If you do a Google search and then link to the search results page, the link shown in the lower left corner of the browser window does not match the actual href element a .
In all three browsers, I tested this if you check the link in the element inspector, although you can easily see the real link (which is located at www.google.com ), and while the inspector is open, if you click on the link again, you will see the real URL link in the lower left corner of the browser window.

Do I have two questions regarding this behavior?

  • Although it might be a bit naive to ask why Google does this?
  • How does google do this? Since I saw this behavior in Chrome, Firefox, and IE11, I think this is JavaScript-driven behavior (as opposed to browser-driven behavior), but I never heard that this was possible in JavaScript. If possible in JavaScript, how do you do this?

Thanks.

+6
source share
3 answers

Look at the initial markup:

 <a onmousedown="return rwt(this,'','','','3','AFQjCNF8xnW_qOvuZURbtcZUvB6zhKtRQw','35cXyZwuoZY8hBY1VfDr8Q','0CEAQFjAC','','',event)" href="http://en.wikipedia.org/wiki/How_Do_You_Do_It%3F"> <em>How Do You Do It</em>? - Wikipedia, the free encyclopedia </a> 

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

 http://www.google.de/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&cad=rja&ved=0CEAQFjAC&url=http%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHow_Do_You_Do_It%253F&ei=8nSMUqXtLKfe4QSzwIDADQ&usg=AFQjCNF8xnW_qOvuZURbtcZUvB6zhKtRQw&sig2=35cXyZwuoZY8hBY1VfDr8Q&bvm=bv.56643336,d.bGE 

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

+9
source

The link on the results page points to the redirect page on the Google server. They do this to track which links people click on. This is more reliable than using Javascript, as it does not require users to enable Javascript.

You can see the final target of the link in the url parameter of the URL.

+2
source

When the user clicks the href button, the onmousedown event handler is onmousedown before the default behavior. This time interval is used to change the href of the anchor label.

Check out this simplified version of your code:

 <a href="https://www.google.com/" data-href='https://www.yahoo.com/' onmousedown="this.href = this.dataset.href" >Link</a> 
+1
source

Source: https://habr.com/ru/post/958453/


All Articles