jquery - Can I trigger an event with javascript redirect? - Stack Overflow

I have a redirect:<script>setTimeout(function() { window.location = ''; }, 2000);<

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
 |  Show 4 more ments

1 Answer 1

Reset to default 3

Set 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');
    }
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744794427a4594118.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信