Search code examples
htmlhyperlinkmailto

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


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="mailto:[email protected]">email</a>

Any ideas?


Solution

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

    <a href="mailto:[email protected]" onclick="window.location=another.html">email</a>
    

    Update:

    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
       window.open = 'anotherpage.html'; //or window.location for redirection
    }
    

    HTML

    <a onclick="handleClick()" href="mailto:[email protected]">email.com</a>