0

I am having errors with the redirect. It is taking me to the following page www.home.com/SITE1/undefined

I am implementing cookies and I think this might be the problem. The reason for the cookie is that I do not want the user to be prompted when they click back. The modal serves as a quick path to commonly used webpages. So I am going to include my complete code. I utilized 90% of this modal with the cookie function. I only wanted to modified it to include 3 more buttons.

Modal.aspx (page rendered inside the modal)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1">
<meta name="WebPartPageExpansion" content="full" />
    <style type="text/css">
        ul,ol {text-align: left;}
        li {list-style-type: circle; padding-top: 15px;}
        .subcontent {width: 500px; margin: 0 auto;}
        .domainName {color: Navy; font-weight: bold;}
    </style>
    <script type="text/javascript">
    function closePage(redirectURL) {
        createCookie("Test", "ACCEPTED");
        SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, redirectURL);
    }

    function createCookie(name, value) {
        var expires = "";
       document.cookie = name + "=" + value + expires + "; path=/";
    }
    </script>
</head>
<body style="text-align: center;">
    <form name="form1" method="post" action="Modal.aspx?IsDlg=1" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wPDwUKLTcxMDYyNDk4OA9kFgICBA9kFgICAQ8WAh4HVmlzaWJsZWdkZJ+th6rM5boAX+jz8z6RusiKXoWY" />
</div>

<div>

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgK83aGICgKUxcvrDpIDY1zrMzRi62kcWf2pzau3Dch0" />
</div>
        <div id="ExSection">

            </div>
                <input type="submit" name="btn1" value="SITE 1" onclick="closePage('www.home.com/SITE1');" id="btn1" />
                <input type="submit" name="btn2" value="SITE 2" onclick="closePage('www.home.com/SITE2');" id="btn2" />
                <input type="submit" name="btn3" value="SITE 3" onclick="closePage('www.home.com/SITE3');" id="btn3" />
            </div>  
    </form>

The CEWP on the parent page

<script type="text/javascript">
function LoadDialog () {
    SP.UI.ModalDialog.showModalDialog({
        title: "TEST MODAL BOX",
        url:    "www.home.com/Modal.aspx",
        width:  800,
        heigth: 600,
        dialogReturnValueCallback: dialogCallback

    });

}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
}

function LoadDialogWrapper() {
    var x = readCookie('Test');
        if (!x) {
    setTimeout("LoadDialog()", 1000);
        }
}
function dialogCallback(dialogResult, returnValue) {
    if(dialogResult== SP.UI.DialogResult.OK)
    {
        window.location.href = returnValue;
        }

}
_spBodyOnLoadFunctionNames.push("LoadDialogWrapper");
</script>

2 Answers 2

1

Firstly in the modal dialog page create 3 buttons:

   <input type="submit" name="btn1" value="Site 1" onclick="closePage('Site1URL');" id="btn1" />
    <input type="submit" name="btn2" value="Site 2" onclick="closePage('Site2URL');" id="btn2" />
    <input type="submit" name="btn3" value="Site 3" onclick="closePage('Site3URL');" id="btn3" />

Then in the javascript method:

function closePage(redirectURL)
{
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, redirectURL);
}

Now in the parent page:

function dialogCallback(dialogResult, returnValue) {
if(dialogResult== SP.UI.DialogResult.OK)
{
window.location.href = returnValue;
}
}
5
  • Could you help me with my revised code?
    – JA1
    Commented Mar 19, 2014 at 21:07
  • @Jeremy don't use window.frameElement.commitPopup(). Use only SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, redirectURL); to close the pop up.
    – Unnie
    Commented Mar 20, 2014 at 5:07
  • It says SP is undefined this break occurs here at the SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, redirectURL);
    – JA1
    Commented Mar 20, 2014 at 11:34
  • @Jeremy make sure 'sp.ui.dialog.js' is loaded in the modal dialog page.
    – Unnie
    Commented Mar 20, 2014 at 17:41
  • I was loading SP.js and SP.core.js I thought these will work I will give that a try thanks
    – JA1
    Commented Mar 20, 2014 at 22:33
0

See this link then you can understand how to take multiple buttons. http://www.tekritisoftware.com/sharepoint-custom-modal-pop-up-confirmation-dialog-box

For closing Dialogbox use: window.frameElement.commonModalDialogClose();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.