How to make the browser back button close a modal window?

Hey everyone! :wave:

I just created a modal window on my new site and I want to setup the following interaction:

Clicking the browser back button should close the window. It should not take the user to a different URL.

Click the Check one out button to open the modal on the site: https://letterloop.webflow.io/

My first thought on how to do this is to give the modal an ID (which it already has), so that the modal opens a URL like “Letterloop: The Newsletter for Friends & Family”, and the back button just goes to the root URL.

But I realized I didn’t have a way to select the back button to trigger this. And I’m not even sure if this is the right approach.

The other thing to note is that my landing page has multiple modal windows you can open. So, clicking the back button will have to close whatever modal window is presently open — not just a specific one.

Has anyone done something like this before? Any help would be greatly appreciated!

Best,

Jonathan


Here is my public share link: https://letterloop.webflow.io/
(It’s still a WIP so forgive some of the UI/UX bugs :stuck_out_tongue:)

Review the following link for options with custom code.