javascriptsettimeouthttp-redirectjquery-blockui

Javascript Redirect use with blockUI and setTimeOut


I use to Javascript page use $.blockUI in a function and I want 3 second block this page. That's why I added to setTimeOut but this function called to Redirect function after blockUI. Don't working setTimeOut in this code or called Redirect function.

How can I do it?

    $.blockUI({
       message: "block message",
        css: {
            border: 'none',
            padding: '15px'
        }
    });
    setTimeout($.unblockUI, 3000);
    URL.Redirect("RedirectURLfunctionName");

Solution

  • In your code it will not wait for setTimeout timeout will only be executed after all the code in a block has finished executing.
    onUnblock callback is invoked when all the blocking elements have been removed

    $.blockUI({
        message: "block message",
        css: {
            border: 'none',
            padding: '15px'
        }
    })
    
    setTimeout(function () {
        $.unblockUI({
            onUnblock: function () { URL.Redirect("RedirectURLfunctionName"); }
        });
    }, 3000);