Is there a way to keep a bootstrap modal open when leaving the page with it, then coming back to said page with your browser's back button?
Asked
Active
Viewed 1,883 times
0
-
Do you mean popping the modal on a page on your site, then say going to Google.com, then hitting the back button to return to your site and the modal is still popped? Either way, what have you done to try and solve the problem yourself? Finally, shy of storing something on the user's machine, the answer is likely no. – MattD Jan 09 '15 at 19:46
-
@MattD Yes, the google scenario is a perfect example. I've done some searching for a solution, but haven't implemented anything - I'm attempting to helping a friend with a few issues on his personal site. – Lauren F Jan 09 '15 at 20:44
-
1Shy of storing something about the user's session when they navigate away from the page containing the modal you're wanting to pop, I really don't think there's a way to do what you want. Since the modal is part of the page itself and not something the browser produces, it goes away when you leave the page. – MattD Jan 09 '15 at 20:45
1 Answers
0
You should read about the so called bfcache, see Is there a cross-browser onload event when clicking the back button? and How to prevent content being displayed from Back-Forward cache in Firefox? then you should realize that the bfcache saved all states of your page (including the state of JS, DOM). So an open modal should be saved open in the bfcache and so be open when navigate back. You find your modal closed, so what happens.
To navigate to an other page (for instance by clicking a link) triggers closing of the modal (and the bfcache saves the page with a closed modal)
Possible solutions:
- prevent your modal from closing when clicking outside it (see: Prevent Bootstrap Modal from disappearing when clicking outside or pressing escape?)
- enable session and disable bfcache (trigger a reload when navigating back) reopen the modal when the user has visit the page already according your session information

Community
- 1
- 1

Bass Jobsen
- 48,736
- 16
- 143
- 224