1

I have an application page which takes some inputs for list creation. Based on these inputs, i am using JavaScript Client Object model to create a new list.
Once the list is created a notification message is displayed. Is it possible to redirect to another SharePoint page using JavaScript CSOM (after the notification is displayed) ?

Update : I tried with window.location.href and the redirection is working fine. I am wondering if the same can be done using JS CSOM.

SP.UI.Notify.addNotification(Message,false);
window.setTimeout(function(){window.location.href=redirectionURL;},5000);
0

2 Answers 2

2

I don't know if there is a built in function in SharePoint for detecting it, like a callback or something. But you could maybe do it with DOMNodeRemoved

PS: Browser support for that event im not sure about, you'll have to check that out if users have older browser.

function AddNotification() {
   var notifyId = SP.UI.Notify.addNotification("Message", false);

   $(document).bind("DOMNodeRemoved", function(e)
    {
        if(e.target.id == notifyId) 
        { 
               // Add redirect script here
            alert("Removed: " + e.target.id); 
        }  
    });

}

AddNotification();

I'm not sure what you mean abut JSOM redirect, because in the end its the same it does as location.href more or less. But there is a built in "redirect" function:

SP.Utilities.HttpUtility.navigateTo

It usese the STSNavigate function from sp.core.js:

function STSNavigate(Url)
{ULSxSy:;
    if (window.location.search.indexOf("IsDlg=1") !=-1)
    {
        if (Url.indexOf("?") !=-1)
        {
            if (Url.match("&$") !="&")
            {
                Url=Url+"&IsDlg=1";
            }
            else
            {
                Url=Url+"IsDlg=1";
            }
        }
        else
        {
            Url=Url+"?IsDlg=1";
        }
    }
    if (isPortalTemplatePage(Url))
        window.top.location=STSPageUrlValidation(Url);
    else
        window.location=STSPageUrlValidation(Url);
}

As you can see, its just does some checks, and then set window.location

1
  • Thanks for the help. SP.Utilities.HttpUtility.navigateTo(url); worked too. +1 for the details. :) Commented Jun 13, 2014 at 9:53
2

I am not sure this is relevant, but I had done something very similar. I had used SP.UI.ModalDialog. You can add options to it and can have a callback fuction that triggers whenever events occour(eg. dialog is closed). You can have the code for redirecting in this callback function.

http://www.ashokraja.me/articles/How-to-redirect-reload-or-refresh-a-page-after-closing-the-SharePoint-2013-Modal-Popup-Dialog might help

Let me know if it helps

2
  • Thanks. Window.location.href works. But i was wondering if there is any option available through JS CSOM ? Commented Jun 13, 2014 at 7:48
  • Is there any specific requirement, like you want to send data present in the source page to the destination link? Commented Jun 13, 2014 at 7:56

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.