Streaming live at 10am (PST)

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:

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 “”, 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!



Here is my public share link:
(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.