Thursday 5 December 2013

Make an anchor tag with href but do not let user navigate away

This can be utilized a lot for SEO purposes. Anchor tag href would be crawled by search engines, but when user will be click, it will not navigate away the user from the page, and you can handle the onclick even in anyway you want to.

<a href="http://www.google.com" onclick="dothis(event); return false;">Click me</a>

<script>
function dothis(e){
if (!e) var e = window.event;
alert("ok");
if (e.stopPropagation)
e.stopPropagation();
return false;
}
</script>