我可以使用 javascript 重定向触发事件吗?

Can I trigger an event with javascript redirect?

我有一个重定向:

<script>setTimeout(function() { window.location = '/'; }, 2000);</script>

效果很好,但我想 "trigger the event":

$('#languagepopup').modal('show')

同时

在 html 中,我会使用类似这样的按钮:

onclick="$('#languagepopup').modal('show')"

如何使用重定向来做到这一点?

非常感谢任何帮助!

像这样在 URL 中设置哈希:

<script>setTimeout(function() { window.location = '/#showModal'; }, 2000);</script>

然后在准备好的处理程序中,查找散列并显示您的模态

$(document).ready(function () {
    if (window.location.hash.indexOf('showModal') !== -1) {
        window.location.hash = ''; // remove the hash
        jQuery('#languagepopup').modal('show');
    }
});