How do I time a modal pop up?

血红的双手。 提交于 2019-12-25 04:38:06

问题


I have a function that does some database update in asp.net. I'd like a modal popup to show a "success" message for just 5 seconds after my function has been called. In this case, the modal popup would not be triggered by any "TargetControl" but would show up for just 5 seconds once the function is done.

Thanks


回答1:


You can't close standard javascript modal dialogs (alert, confirm,..) after a timeout. Only manual close works with them.

But, you can use jquery/UI dialog:

// timeOut in ms
function showMessageWithTiemout(message, timeOut){

    // show dialog
    var successDialog = $('<div>'+message+'</div>').dialog({modal: true});  

    //close it after 5 seconds
    setTimeout(function(){ successDialog.dialog('close'); }, timeOut);

}

//usage:
showMessageWithTiemout('success!', 5000);



回答2:


You have to manually call the show method on the panel like:

var pnl = $find("<%= modal.ClientID");
pnl.show();

So you can use window.setTimeout to call this:

window.setTimeout(function() { /* code */ }, 5000);

But it can't just happen very easily.

HTH.



来源:https://stackoverflow.com/questions/5666499/how-do-i-time-a-modal-pop-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!