am having an editform.aspx page in my SPO site. am using presaveitem() in my content editor web part to perform validation and etc after completion of calling of presaveitem(), i ant to stay on the same page , ie, i wanna stay like : https://mycustomersposite/msite/lists/splist1/editform.aspx?ID=425 with the same ID, after refreshing the page automatically.

 function Presaveitem()
 //perform validation .. etc 

   alert("Item is updated successfully on 11/05 monday");
   alert('reloading the page');

return true;

The problem am facing is, after click on the save button, its automatically redirecting to the AllItems.aspx page always. what my understanding is if i call just before closing of Presaveitem() fun.call
window.location.reload(); , it will reload the page with the latest updates happened to the list items id , mentioned in the ?ID=mylistitemidnumber . How to stop redirecting to the allitems.aspx page from editform? is it possible to add a ?source param in the URL, ( inject it on page load) automatically/programmatically?

  • First of all, the meaning of presaveitem is that it is called before saving the item. Why would you write saving functionality inside presaveitem? There are multiple ways to achieve it. Do you have the freedom to edit the forms in designer? Commented Nov 5, 2018 at 17:38
  • @harshal, if i create a new custom form in SP designer, what i have observed that, i am unable to add a content editor wbe part in that custom form. its showing weird behaviour. so, i thought of using the existing,default newform, editform pages
    – dasarp
    Commented Nov 6, 2018 at 11:17
  • "there are multiple ways to achieve it." --> can you please elaborate it and what are the ways to achieve it. help is appreciated!
    – dasarp
    Commented Nov 6, 2018 at 11:19
  • If you sant to use the default form, then you can override the submit button action and redirect after saving. Commented Nov 6, 2018 at 11:22

1 Answer 1


Please find the screenshot of edit page with script editor web part and after addming the web part how your edit form URL looks likeThis block of code helped me in the past. Add a script editor on the edit form and paste the code in the script editor web part.

    window.history.pushState("object or string", "Title",window.location.href+"?Source=http://YourPageURL");
  • are you saying that, just before closing the presaveitem(), i dont need to reload the page --> no need to call .reload()??
    – dasarp
    Commented Nov 5, 2018 at 10:04
  • 1
    After the source attribute, use edit form url, it will reload the current page. you should use exact the following line of code. window.history.pushState("object or string", "Title", window.location.href+"?Source="+window.location.href); Commented Nov 5, 2018 at 10:25
  • after adding your code, it seems, the values are not getting saved into the splist. it loaded with the old values. i think, its not committing in the DB.
    – dasarp
    Commented Nov 5, 2018 at 11:15
  • I tried it with my splist and it worked well for me please see the screenshot attached Commented Nov 5, 2018 at 15:25

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.