2

If you search something in Google (e.g. StackOverFlow), in search result page you can see the StackOverFlow item as result.

When you hover mouse in StackOverFlow item browser shows that it's an anchor element refers to stackoverflow.com . But when you right click on the item and click on copy link address the url is this .

How does Google do it?

ahmadali shafiee
  • 4,350
  • 12
  • 56
  • 91
  • 1
    The URL you get is redirection URL – Mr. Alien May 20 '13 at 06:48
  • I think they send you to StackOverflow to make some statistics. – Gustaf Rosenblad May 20 '13 at 06:49
  • @Mr.Alien I know that it redirect you to stackoverflow. but google use it for analytics or other things – ahmadali shafiee May 20 '13 at 06:49
  • @GustafRosenblad I know. I said `When you hover mouse in StackOverFlow item browser shows that it's an anchor element refers to stackoverflow.com . But when you right click on the item and click on copy link address the url is this.` I wanna know how google changes the href link. – ahmadali shafiee May 20 '13 at 06:50
  • i think it is simply done with JS. for example http://stackoverflow.com/questions/1629285/how-to-use-jquery-click-event-to-change-href-value-asyncronously-based-on-a-jso – fsw May 20 '13 at 07:20
  • @fsw if it was simple js then `Copy link address` should copy the site url instead of `google.com/url` url! – ahmadali shafiee May 26 '13 at 09:51
  • http://api.jquery.com/mousedown/ works on left and right click. please note that if you hover on element it has the "right" url and after right click it gets changed to googly one. so change href on mouseover. also seems like a duplicate of http://stackoverflow.com/questions/2813648/how-do-google-and-yahoo-replace-the-url-in-the-browser-status-bar – fsw May 26 '13 at 17:08

1 Answers1

2
<a id="changeMe" href="http://foo.com">click me</a>

as mentioned in comments guess this is as simple as:

$('#changeMe').mousedown(function(){
  $(this).attr('href', "http://bar.com")  
});

http://jsfiddle.net/jpkL6/

fsw
  • 3,595
  • 3
  • 20
  • 34