0

I have a Custom List called "Items" When a user Views or Edits an item in this list I would like the Close or Save button to redirect the user to the home page and not the Default "All Items" of the list.

How can I accomplish this?

2 Answers 2

1

Using the below code you can achieve this. It allows to set the redirection on the client-side

$(document).ready(function() {

    var button = $("input[id$=SaveItem]");
    // change redirection behavior
        button.removeAttr("onclick");
        button.click(function() {
            var elementName = $(this).attr("name");
            var aspForm = $("form[name=aspnetForm]");
            var oldPostbackUrl = aspForm.get(0).action;
            var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
            var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "MyRedirectionDestination.aspx");

            if (!PreSaveItem()) return false;
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
        });

});

Source : Link

4
  • Forgive me for the newbie question. How or where do I add this code to my page to use this code?
    – ITT4R CORP
    May 18, 2016 at 12:10
  • Simply SPD 2013 or else use Script editor web part on the page do you want to do this functionality. May 18, 2016 at 12:17
  • ok so I added a Script Editor to my New Item page, but nothing happens when I save the item, it still returns to the default all items view
    – ITT4R CORP
    May 18, 2016 at 16:08
  • Give your custom redirect home page Url in newPostbackUrl May 19, 2016 at 6:24
0

Using below mentioned trick you can change the button's redirection behavior in Display or Edit form.

Change SharePoint List “Display Item Form” Close Button Default Redirect Location

I hope it works for you.

Thanks.

2
  • Is this solution works as per your need?
    – Hardik
    May 19, 2016 at 12:18
  • Hello man is that works for you? did you achieved it?
    – Hardik
    Jun 14, 2016 at 18:50

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.