?redirect=
in link hrefs with data-redirect="true"
or in the browser address bar without reloading the page.To dynamically update the URL parameter after ?redirect=
to reflect the current page URL in Webflow, you’ll need to use JavaScript at runtime in the browser.
DOMContentLoaded
).Use the following logic:
Get the current page URL.
Update or add the ?redirect=
parameter in links or in the browser’s address bar.
Example script to update a link with ?redirect=currentUrl
:
<script> document.addEventListener("DOMContentLoaded", function () { const links = document.querySelectorAll('a[data-redirect="true"]'); const currentUrl = window.location.href; links.forEach(link => { const baseHref = link.href.split('?')[0]; link.href = `${baseHref}?redirect=${encodeURIComponent(currentUrl)}`; }); });</script>
data-redirect="true"
to any link you want to dynamically set.redirect=
parameter in the current page URL without reloading:<script> document.addEventListener("DOMContentLoaded", function () { const url = new URL(window.location); url.searchParams.set('redirect', window.location.href); window.history.replaceState({}, '', url); });</script>
redirect=currentPage
parameter without refreshing the page.To dynamically set ?redirect=
to the current URL in Webflow, add JavaScript in an embed or the footer section. Use window.location.href
to get the current URL, and then update either link destinations or the browser address bar using JavaScript and URL
object methods.