-
Notifications
You must be signed in to change notification settings - Fork 664
Handle back button on Android devices #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
That is how browsers work, when the URL does not change, when you open the modal window, it will call You can work around that, by doing something like this: HTML <button>Click to view the video</button> JavaScript (function(window, document){
$(window).on('popstate', function() {
if(window.location.hash === '#kylefoxrocks') {
$('.jquery-modal').remove();
}
});
$('button').on('click', function(evt) {
evt.preventDefault();
window.location.href = '#kylefoxrocks'
window.location.href = '#modalopened'
var video = document.createElement('video');
var src = document.createElement('source');
video.setAttribute('controls', '');
src.setAttribute('src', 'https://cdn.emkae.net/magic-mike-xxl-i-want-it-that-way.mp4');
src.setAttribute('type', 'video/mp4');
video.appendChild(src);
$(video).appendTo('body').modal();
});
})(window, document); See the Demo |
I have the same issue using Kyle Fox modal in my single page website where I load external content in full screen modal. The user leaves website when he taps browser back button instead of modal close button. I try to resolving it by manipulating the history API with Jquery. Any help ? Here is an example code: Index page:
Content load in modal (ajax-content.html):
Jquery:
Any help would be most welcome ? |
Hi,
This works great on my website but when the modal is opened and viewed on an Android device and then the user taps their back button, the mobile browser leaves/closes the website.
To reproduce, open jquery-modal on an Android phone and then tap the back button.
Is there any way the back button can just close the modal?
Thanks!
The text was updated successfully, but these errors were encountered: