Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show javascript Alert without blocking javascript

On page load, I am starting a timer to check if session is expired. I am checking expiry by making ajax call to a page. I need to display alert 5 minutes before expiry and redirect to default page after expiry. Here is my code:

function startSessionCheckTimer() {
    setInterval(checkSessionExpiry, 60000);
}

function checkSessionExpiry() {
    $.ajax({
        type: "POST",
        url: "/Default.aspx/IsSessionOpen",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (time) {
            if (time.d == 5) {
                //alert("Your session will expire in 5 minutes.");
                setTimeout(function () { alert('Your session will expire in 5 minutes.'); }, 100);
            }
            else if (time.d <= 0) {
                window.location = "/Default.aspx";
            }
        }
    });
}

Alert is displayed after 5 minutes, but if user does not click OK, it blocks the javascript and no further ajax calls are made.

Is there a way that I can display Alert without blocking it? I do not want to using jQuery dialog.

like image 601
Tushar Kesare Avatar asked Feb 13 '23 00:02

Tushar Kesare


1 Answers

No, there is no way to display a native alert without halting the execution of the script.

The only way is to use a dialog or something that is not a native alert

http://jqueryui.com/dialog/

like image 106
adeneo Avatar answered Feb 15 '23 18:02

adeneo