How can I prevent the "mailto" function in Webflow from opening an empty new tab along with the email client?

TL;DR
  • Uncheck "Open in New Tab" in Webflow link settings for "mailto" links.
  • Use a custom JavaScript script to prevent empty tabs from opening with the link.
  • Test in Webflow Preview to ensure the email client opens correctly without an empty tab.

When using a mailto link in Webflow, it can sometimes open an unwanted empty tab. Here's how you can prevent this:

1. Modify the Link Settings

  • Open the Link Settings for the specific mailto link in your Webflow project.
  • Make sure to uncheck the option that says "Open in New Tab."

2. Use Custom Code

  • Insert a small piece of custom JavaScript in your project to handle mailto links correctly.
  • Embed the following script in the "Before </body> tag" section under the Project Settings > Custom Code:
  • Create a script element and add DOM content loader logic. Use event.preventDefault() for mailto links within the logic to ensure no empty tabs are opened. Remember, inline code snippets should not be shared according to the given rules, so configure your script accordingly without explicit example code.

3. Test in Webflow Preview

  • Preview your site in Webflow to ensure the mailto link behaves as expected.
  • Ensure the email client opens without an additional empty tab.

Summary

To prevent a "mailto" link in Webflow from opening an empty tab, uncheck the "Open in New Tab" option in Link Settings and potentially use a small custom script to handle the link correctly. Always test the link to confirm it works without issues.

Rate this answer

Other Webflow Questions