Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);
share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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

share|improve this answer
    
Thanks for the help. SP.Utilities.HttpUtility.navigateTo(url); worked too. +1 for the details. :) –  Thomas Mathew Jun 13 at 9:53
add comment

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

share|improve this answer
    
Thanks. Window.location.href works. But i was wondering if there is any option available through JS CSOM ? –  Thomas Mathew Jun 13 at 7:48
    
Is there any specific requirement, like you want to send data present in the source page to the destination link? –  Swayam S. Jun 13 at 7:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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