March 31, 2012

How to make a link navigate to another page and also mailto an email?

Question by Doug Firr

I’d like a link where if someone clicks a mailto link they are also shown a different page.

What would the html look like? Currently:

<a href="">email</a>

Any ideas?

Answer by Starx

Use Javascript’s window.location on the click event of the link

<a href="" onclick="window.location=another.html">email</a>


If you have to stack up lots of code in the onclick event, create a function instead

function handleClick() { 
   _gaq.push(['_trackEvent', 'emails', 'clicked', 'lead']); //first this = 'anotherpage.html'; //or window.location for redirection


<a onclick="handleClick()" href=""></a>

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+


Please fill the form - I will response as fast as I can!