是否可以在页面刷新时停止关闭Jquery模态弹出窗口? [英] Is it possible to stop closing Jquery modal popup on page refreshing?

查看:90
本文介绍了是否可以在页面刷新时停止关闭Jquery模态弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个MVC4应用程序,该应用程序在Modal弹出窗口中显示一些信息.我能够显示所需的信息.如果在Modal打开时刷新页面,则当前Modal将关闭.有什么方法可以停止在页面刷新时关闭模式吗?

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?

这是我的模态代码.

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模式代码

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);
                }
            },
});
});

推荐答案

使用localStorage()设置弹出窗口的当前状态.

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");     
   }
});

最后,您可以从localStorage项目中删除该项目

Finally, you can remove the item from localStorage item

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

仅供参考,要使用localStorage,您的浏览器应支持HTML5.

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

参考

HTML5本地存储

这篇关于是否可以在页面刷新时停止关闭Jquery模态弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆