Sunday, November 9, 2025

Outlinks With Return-To

This is a sample blog post with out-links that access iNat data.  

Sample Out-Link:
Wildlife Activity

If I only wanted to see wildlife activity on goldenrods...
Wildlife Activity ~ Only Goldenrods

A "return to" parameter is automatically appended to the end of the url using the following javascript that's been added to a widget in the footer. 



<script> // append return_to to the end of outlinks

document.addEventListener('DOMContentLoaded', function() {

  var pageUrl = encodeURIComponent(window.location.href); 

  document.querySelectorAll('a').forEach(function(anchor) {

    // targets links that point to stockslager github repo

    if (anchor.href.includes('stockslager') ||

anchor.hostname.includes('stockslager') ) {

      const separator = anchor.href.includes('?') ? '&' : '?';

      anchor.href = `${anchor.href}${separator}returnto=${pageUrl}`;

    }

  });

});

</script>