简体   繁体   中英

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.

I have the following situation. In a webpart I am opening another webpart into a modal dialog (and this is not a problem). Then, when the modal dialog is closed, I have to refresh the parent page (not the dialog that is closed) into another webpart. I am trying to implement this behavior via JavaScript, in this way:

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).

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. 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM