Redirect to New URL Script

Hello I have the code below that allows you to redirect to a new URL when the form is save. It works but whenever click add new item it reloads the page twice in SHAREPOINT. Can someone help me fix this?

<script src="" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script> ​​​<br/><script type="text/javascript">




location.href = _spPageContextInfo.webAbsoluteUrl; // It will redirect you to home page after clicking on cancel button


var stringURL = location.href;
stringURL = stringURL.replace(stringURL.substring(stringURL.indexOf("Source="),stringURL.length),'Source='+_spPageContextInfo.webAbsoluteUrl+'/SitePages/ThankYou.aspx');
location.href = stringURL;

location.href = location.href+"?Source="+_spPageContextInfo.webAbsoluteUrl+'/SitePages/ThankYou.aspx';




Hi @surajkay19, then your script probably runs into one of the two if conditions after the redirect, causing another redirect… what is the value of _spPageContextInfo.webAbsoluteUrl here?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.