[英]Close modal dialog WITHOUT refreshing the parent
I need to close my custom form (which I show in modal dialog) and stop the parent site from refreshing. 我需要关闭我的自定义表单(在模式对话框中显示),并停止刷新父站点。
I call my closing function from custom "Cancel" button on click. 单击后,我从自定义“取消”按钮调用关闭函数。
customClose() {
//some code here
window.frameElement.cancelPopUp();
}
<input type="button" value="Cancel" onclick="javascript:customClose()" />
But if I close my dialog this way, it refreshes the parent site. 但是,如果我以这种方式关闭对话框,它将刷新父站点。 How can I close it without refreshing? 如何关闭而不刷新?
PS It's a SharePoint modal dialog. PS这是一个SharePoint模式对话框。
NOTE: I can't use jQuery for this, need pure js. 注意:我不能为此使用jQuery,需要纯js。
SharePoint has some built-in methods for displaying and closing modal dialogs. SharePoint具有一些用于显示和关闭模式对话框的内置方法。
For SharePoint 2010, use the SP.UI.ModalDialog.commonModalDialogClose
method to close the most recently opened modal dialog. 对于SharePoint 2010,请使用SP.UI.ModalDialog.commonModalDialogClose
方法关闭最近打开的模式对话框。
Here's an example that uses commonModalDialogClose
to close a dialog. 这是一个使用commonModalDialogClose
关闭对话框的示例。 The window should not refresh upon closing. 该窗口在关闭时不应刷新。
ExecuteOrDelayUntilScriptLoaded(showDialog,"sp.js");
function showDialog(){
var dialogBody = document.createElement("div");
var btnClose = document.createElement("button");
btnClose.value = "Cancel";
btnClose.innerHTML = "Cancel";
btnClose.onclick = function(){SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel,null);};
dialogBody.appendChild(btnClose);
SP.UI.ModalDialog.showModalDialog(
{
html:dialogBody,
title:"Your Title Here",
dialogReturnValueCallback:onClose
});
}
function onClose(result,data){
// this callback function lets you control what happens after the dialog closes
switch(result){
case SP.UI.DialogResult.invalid:
break;
case SP.UI.DialogResult.cancel:
break;
case SP.UI.DialogResult.OK:
window.location.reload();
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.