简体   繁体   English

为什么在SharePoint中关闭模式对话框时无法重定向到另一个URL?

[英]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.

相关问题 为什么当我设置 data-backdrop = "false" 时,当我在模态之外单击时它无法关闭模态? - Why when I set data-backdrop = "false", it can't close modal when I click outside of modal? Beforeunload无法将用户重定向到另一个页面,如何在尝试关闭窗口/选项卡时将用户重定向到另一个页面/ URL? - Beforeunload is not working to redirect user to another page, how can I redirect user to another page/url when he attempts to close a window/tab? 当我点击它外部时无法关闭模式 - Can't close modal when I click outside of it 当我单击关闭选项卡或关闭浏览器窗口时,是否可以将页面重定向到另一个URL? - Is is possible to redirect a page to another url when i click on to the close tab or close a browser window? 我无法在jointJS中关闭对话框 - I can't close dialog in jointJS 如何将 url 重定向到另一个 url? - how can I redirect a url to another url? 为什么在那之后我关闭了定义到子组件中的 PrimeNG 模态我无法再次打开它? - Why after that I close a PrimeNG modal defined into a child component I can't open it again? 关闭模式弹出窗口后,如何重定向到模式弹出窗口中的第一个选项卡? - How can I redirect to first tab in modal popup after I close the modal popup? 为什么我无法在模态中管理状态以使用redux打开和关闭? - Why can't I manage the state in my modal to open and close using redux? 当我在外面单击时,为什么我的js模式没有关闭? - Why does my js modal not close when I click outside?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM