How can I creat a link that open a url when we use "open in new tab / window from browser menu" and when we click on self page just run a javascript function not redirect.

I want create some links that when we click on them update some parts of pages with Ajax and disable redirecting and when we click open in new window it redirect (I saw some sample in web)