0

I've seen this in a number of websites in all browsers. When you hover over a link, a preview of the URL is displayed somewhere in the browser, and the URL is to a specific webpage such as www.google.com. However, when you click on it, another page is called instead which then eventually redirects to the originally previewed link, such as www.somedomain.com/openurl?url=www.google.com. The purpose of such a feature is to wrap links in a common "click counter" so every link which is clicked is deliberately redirected through a common server which in turn redirects to the original URL.

How do I accomplish this in any type of HTML page? Doesn't matter if it's specific to HTML 4 or 5, I just want to know the fundamentals of how it's done. If I knew the terminology I would have googled it.

PS - I'm not talking about URL Re-writing which is the address bar - I'm talking when you hover over a hyperlink and the browser shows you a preview.

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • You can do it by intercepting the `mouseover` event and writing to the status bar, but why would you? I can think of only nefarious reasons for doing something like that. – Kevin Boucher May 11 '13 at 01:08
  • @Kevin it's for click counting, keeping track of when people click a particular link - but letting the user see what the link actually leads to. Many popular sites have this such as Google and Facebook. – Jerry Dodge May 11 '13 at 13:29

1 Answers1

1

Most likely with javascript, using a click event handler on the link.

Here's a basic example:

<a href="http://google.com" 
   onclick="window.location.href='http://stackoverflow.com'; return false;">

   clicky
</a>
nice ass
  • 16,471
  • 7
  • 50
  • 89
  • Any mention to browser compatibility for this? I mean I know the `onclick` event is the way to go, but I just need to make sure the specific implementation is adequate for all browsers. – Jerry Dodge May 11 '13 at 01:46
  • It works in all browsers if javascript is enabled, but it's not the recommended way of attaching click handlers. See [this Q](http://stackoverflow.com/questions/6348494/addeventlistener-vs-onclick) why – nice ass May 11 '13 at 09:39