I have a redirect:
<script>setTimeout(function() { window.location = '/'; }, 2000);</script>
That works perfectly, but I'd like to "trigger the event":
$('#languagepopup').modal('show')
at the same time.
In html I would use a button with something like:
onclick="$('#languagepopup').modal('show')"
How can I do that with the redirect?
Any help highly appreciated!
I have a redirect:
<script>setTimeout(function() { window.location = '/'; }, 2000);</script>
That works perfectly, but I'd like to "trigger the event":
$('#languagepopup').modal('show')
at the same time.
In html I would use a button with something like:
onclick="$('#languagepopup').modal('show')"
How can I do that with the redirect?
Any help highly appreciated!
Share Improve this question asked Jan 18, 2015 at 22:40 tomtomtomtom 991 gold badge1 silver badge10 bronze badges 9- 2 You need to pass a parameter to the page and read it with JS there. – SLaks Commented Jan 18, 2015 at 22:42
- possible duplicate of Event when window.location.href changes – Etheryte Commented Jan 18, 2015 at 22:44
- Do you mean show the modal when the page you are redirecting to loads? – unobf Commented Jan 18, 2015 at 22:52
- You cannot do this at the same time since the current context will be lost as soon as the page is requested. However you can handle this on the page you are redirecting to. – IsakBosman Commented Jan 18, 2015 at 22:59
- @unobf yes, that is my objective – tomtom Commented Jan 18, 2015 at 22:59
1 Answer
Reset to default 3Set a hash in the URL like this:
<script>setTimeout(function() { window.location = '/#showModal'; }, 2000);</script>
and then in the ready handler, look for the hash and show your modal
$(document).ready(function () {
if (window.location.hash.indexOf('showModal') !== -1) {
window.location.hash = ''; // remove the hash
jQuery('#languagepopup').modal('show');
}
});