如何在调用回调之前停止 javascript 执行

How to hault the javascript execution before calling a callback

调用 alert 将暂停执行,直到用户按下 "Ok"。使用 sweetAlerts 是否可以实现相同的暂停效果?

刷新网站的回调现在立即完成,因此用户没有时间阅读 sweetAlert。 在用户按下 "Ok" 并且网站将自动刷新之前,我想给用户时间阅读消息。

linkingOrUnlinkingDone = function (result) {
    alert('This will wait for the user to click the button');
    swal(result.text,
        hardcodedTextHelper.siteAutomaticallyRefresh(),
        result.type.toLowerCase(),
        window.location.reload(false)
    );
},

根据examples provided on SweetAlert github,在点击SweetAlert中的按钮后用于触发函数的语法如下:

swal({
    title: "", // Your titles goes here
    text: "", // Your text goes here
    type: "", // Your text goes here
}, function(){
    // Your refresh function goes here
});

关于您提供的代码,您可能知道当您通过 hardcodedTextHelper.siteAutomaticallyRefresh()window.location.reload(false) 作为参数,这些函数会被立即调用:hardcodedTextHelper.siteAutomaticallyRefresh 是对函数的引用,hardcodedTextHelper.siteAutomaticallyRefresh() 是对该函数的调用。