Skip to content Skip to sidebar Skip to footer

How To Prevent Page From Jumping To Top Of Page With Mailto Link In An Anchor?

I have an anchor link with mailto:example@email.com as href, but it jumps to the top of the page when it is clicked. I want to prevent that from happening. I tried e.preventDefault

Solution 1:

Instead of writing:

<aclass="get-in-touch"href="mailto:email@gmail.com">Get In Touch</a>

Write the following:

<aclass="get-in-touch"href="#"onclick="window.open('mailto:email@gmail.com')">Get In Touch</a>

This will work surely.

Here is another stackoverflow question regarding your problem.

Here is the link to the jsfiddle.

Post a Comment for "How To Prevent Page From Jumping To Top Of Page With Mailto Link In An Anchor?"