[英]Why I can't redirect to another URL when I close a modal dialog in SharePoint?
very new in SharePoint and I have the following problem implementing a specific modal dialog behavior in SharePoint 2013. 在SharePoint中非常新,我在SharePoint 2013中实现特定的模式对话框行为时遇到以下问题。
I have the following situation. 我有以下情况。 In a webpart I am opening another webpart into a modal dialog (and this is not a problem).
在Webpart中,我正在将另一个WebPart打开到模式对话框中(这不是问题)。 Then, when the modal dialog is closed, I have to refresh the parent page (not the dialog that is closed) into another webpart.
然后,当关闭模式对话框时,我必须将父页面(而不是关闭的对话框)刷新到另一个Web部件中。 I am trying to implement this behavior via JavaScript, in this way:
我正在尝试通过JavaScript以这种方式实现此行为:
string javascript = "function openEdit(link) {" +
"var options = {" +
"url: link," +
"dialogReturnValueCallback: Callback" +
"};" +
"SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);" +
"}" +
"function Callback(dialogResult, ret) {" +
"alert('TEST');" +
"window.frameElement.commitPopup();" +
//"window.location.replace(\"" + linkRed + "\");" +
"window.parent.location.herf = 'http://www.google.com'" +
"}" +
"openEdit(\"" + linkPrint + "\");";
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "CallJS", javascript, true);
As you can see, in my parent webpart I am using the openEdit() JS function to open the link (represented by the value of the linkPrint string variable (it works). 如您所见,在父级Web部件中,我正在使用openEdit() JS函数打开链接(由linkPrint字符串变量的值表示(有效)。
I am also declaring callback function that is called when my modal dialog is closed. 我还声明了关闭我的模式对话框时调用的回调函数。 It correctly enter into this Callback() function (I see it because I put the alert()) but then I expected to be redirected to google.com (or to the URL on another webpart changing this value) but it is not working.
它正确地进入了此Callback()函数(我看到它是因为我放了alert()),但随后我希望将其重定向到google.com(或更改此值的另一个Webpart上的URL),但无法正常工作。 It is redirecting and refreshing the parent page from where I opened my modal dialog window.
它从我打开模态对话框窗口的位置重定向和刷新父页面。
Why? 为什么? What is wrong?
怎么了? What am I missing?
我想念什么? How can I fix this issue?
如何解决此问题?
Modify the code as below. 修改代码如下。 Note: In you code replace " herf " with " href " and use window.location.href to redirect other page.
注意:在代码中,将“ herf ”替换为“ href ”,然后使用window.location.href重定向其他页面。
var linkPrint = "http://sp2013/sites/team/Lists/Test/EditForm.aspx?ID=1";
string javascript = "function openEdit(link) {" +
"var options = {" +
"url: link," +
"dialogReturnValueCallback: Callback" +
"};" +
"SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);" +
"}" +
"function Callback(dialogResult, ret) {" +
"alert('TEST');" +
"window.location.href= 'http://www.google.com';" +
"}" +
"openEdit(\"" + linkPrint + "\");";
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "CallJS", javascript, true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.