event.preventDefault();
will prevent the default behaviour of the click on the element.
So:
<a href="<%#XPath("link").ToString()%>" onclick="event.preventDefault(); return getLink(this)">Link</a>
Question
I have this href link in a control that calls a javascript and pass the variable to it:
<a href="<%#XPath("link").ToString()%>" onclick="return getLink(this)">Link</a>
I need to stop it opening the browser. How can I do that?
Solution
event.preventDefault();
will prevent the default behaviour of the click on the element.
So:
<a href="<%#XPath("link").ToString()%>" onclick="event.preventDefault(); return getLink(this)">Link</a>
OTHER TIPS
If you want to prevent default browser behavior - just return false at onclick
<a href="<%#XPath("link").ToString()%>" onclick="getLink(this); return false;">Link</a>
or make function getLink to return false
Try this:
<a href="javascript:void(0)" onclick="return getLink(this)">Link</a>