How can I disable the target=blank code in Webflow's link properties for an image that links to email, so that it doesn't open a separate tab with ?subject=(subject) in the browser?

TL;DR
  • Access the image link settings and note that Webflow doesn't allow direct removal of target="_blank".
  • Use custom code by adding a JavaScript snippet in the Project Settings under Custom Code to adjust the link's target attribute.

You want to disable the target="_blank" attribute for an email link associated with an image in Webflow to prevent it from opening in a new tab. Here's how:

1. Access Image Link Settings

  • Select the image that is linked to the email.
  • Open the Link Settings panel (the gear icon in the settings toolbar).

2. Customize Link Attributes

  • Webflow does not allow you to directly remove the target="_blank" for email links in its interface.
  • Use custom code to manipulate the attribute after publishing your site.

3. Add Custom Code

  • Go to Project Settings in Webflow.
  • Navigate to the Custom Code section.
  • You'll need to add a script that finds the email link and adjusts its target attribute. This can be included in the "Footer Code" area:
  • Use the following JavaScript snippet contextually: 
  • document.querySelectorAll('a[href^="mailto:"]').forEach(link => link.removeAttribute('target'));
  • Save your changes and publish your site.

Summary

To disable the target="_blank" attribute for an email link related to an image in Webflow, you'll need to use custom JavaScript in the Project Settings. This will remove the attribute from all email links, preventing them from opening in new tabs.

Rate this answer

Other Webflow Questions