Autre

Ouvrir les liens externes dans un nouvel onglet sur desktop

Ouvre tous les liens externes dans un nouvel onglet hormis sur mobile où tous les liens s'ouvrent sur le même onglet (sans à le paramétrer dans Webflow)

Copier ce script

Etape 1

Copier le script et le coller sur votre page ou projet Webflow

<script>

// Function to handle link clicks
function handleLinkClick(event) {
  // Check if the clicked link is internal (on the same domain)
  if (event.target.hostname === window.location.hostname) {
    // Open internal links on the same tab
    return;
  }
  
  // Check if the device is mobile
  if (window.matchMedia('(max-width: 767px)').matches) {
    // Open all links on the same tab on mobile devices
    return;
  }
  
  // Open external links on a new tab
  event.preventDefault();
  window.open(event.target.href, '_blank');
}

// Attach the link click handler to all  elements
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
  links[i].addEventListener('click', handleLinkClick);
}


</script>
Copier

Etape 2

Intégrer sur Webflow en adaptant à votre projet et votre configuration

  • Ajouter ce script dans le body de votre projet