Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
250 views
in Technique[技术] by (71.8m points)

javascript - Is it possible to stop closing Jquery modal popup on page refreshing?

I am developing one MVC4 application where I am displaying some information on Modal popup. I am able to display the required information. If I refresh the page when the Modal is open the current Modal will close. Is there any way to stop closing the Modal on page refresh?

This is my Modal code.

function cancel(upload_Id) {
    if (!$("#formID").validationEngine('validate')) {
        return false;
    }
    $("#id").val(upload_Id);
    $(".reject-popup-inner").parents('div').addClass('reject-popup');
    $("#dialog-form").dialog("open");
}
<div id="dialog-form" title="Reject Reason" class="reject-popup-inner">
    <div>
        <input type="hidden" value="_upload_id" id="id" /><br />
        <label for="name">Select your reason below</label>
        <select id="comments">
            <option value="0">Wrong Document</option>
            <option value="1">Incorrect Document</option>
            <option value="2">document is not clear</option>
            <option value="3">document is not valid</option>
            <option value="4">other document</option>
        </select>
        <input type="button" id="reject" class="btn btn-primary btn-cons blue" value="Ok" onclick="reject();" tabindex="-1" style="float:right;">
    </div>
</div>

jQuery Modal code

 $("#dialog").dialog({
            modal: true,
            title: "Preview of " + FileName,
            width: 850,
            closeOnEscape: false,
            height: 600,
            buttons: {
                Close: function () {
                    $(this).dialog('close');
                    deleteFile(FileName);
                }
            },
});
});
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use localStorage() to set the current state of pop up.

function cancel(upload_Id)
{
    if (!$("#formID").validationEngine('validate')) {
         return false;
    }
    $("#id").val(upload_Id);
    $(".reject-popup-inner").parents('div').addClass('reject-popup');
    $("#dialog-form").dialog("open");
    //Set item in localStorage
    localStorage.setItem('popupFlag', 1);
}

On page load you can check the flag

$(document).ready(function(){
   //Get and Check item in localStorage
   if(localStorage.getItem('popupFlag') == 1)
   {
      $("#dialog-form").dialog("open");     
   }
});

Finally, you can remove the item from localStorage item

//Remove item from localStorage
localStorage.removeItem('popupFlag')

FYI, to use localStorage your browser should be HTML5 supported.

Reference

HTML5 Local Storage


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...