admin管理员组文章数量:1410717
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');
}
});
本文标签: jqueryCan I trigger an event with javascript redirectStack Overflow
版权声明:本文标题:jquery - Can I trigger an event with javascript redirect? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744794426a2625491.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论