我打开弹出窗口,其中包含来自服务器端的以下代码
var url = string.Format("../UserPopup.aspx?user_Ids={0}&fromDate={1}&toDate={2}", user_Ids, fromDate, toDate);
string script = string.Format("function f(){{openDialog('{0}', {1}, {2}, {3});Sys.Application.remove_load(f);}}Sys.Application.add_load(f);",
url,
"true",
1000,
300);
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "someKey", script, true)
以下是从javascript关闭弹出窗口的代码。以下代码无效。
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function Close() {
var result = window.confirm("Are you sure you want to close the window!");
if (result == true) {
var oWindow = GetRadWindow();
oWindow.argument = null;
oWindow.onunload = refreshParent;
oWindow.close();
return false;
}
}
function refreshParent() {
window.opener.location.reload();
}
window.opener.location.reload();
在这里根本不起作用。不知道原因。
如何在弹出窗口关闭时刷新父页面?
答案 0 :(得分:2)
使用OnClientClose事件,例如:
在主页上
<telerik:RadWindow ID="RadWindow1" runat="server" OnClientClose="OnClientClose"></telerik:RadWindow>
<script>
function OnClientClose(sender, args) {
if (args.get_argument()) { //make the condition more complex, depending on the argument you pass
window.location.href = window.location.href;
}
}
</script>
在内容页面
function Close() {
var result = window.confirm("Are you sure you want to close the window!");
if (result == true) {
var oWindow = GetRadWindow();
oWindow.close(someArugment); //pass the argument here. Define it first, of course
}
}
答案 1 :(得分:-1)
您可以使用局部视图模型,首先将以下代码添加到局部视图中,然后在主视图中添加“mymodel”,
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Event Information</h4>
</div>
<div id='myModal' class='modal'>
<div class="modal-dialog">
<div class="modal-content">
<div id='myModalContent'></div>
</div>
</div>
</div>
现在这里是你的关闭按钮javascript文件,其中只隐藏'mymodel'控件
$(function () {
$("#closbtn").click(function () {
$('#myModal').modal('hide');
});
});