is there some way to replace the Source query string parameter in SharePoint without redirecting the user? All the examples I find use location.href="new url"; which causes the page to immediately reload. However, I just want to actually replace the Source parameter so Sharepoint will redirect to it after the user is done with whatever he is doing.
I already managed to replace the query string with the following code:
$(document).ready(() => {
var redirectUrl = _spPageContextInfo.webAbsoluteUrl + "/" + _spPageContextInfo.layoutsUrl + "/Redirect.aspx";
var queryParameters = {}, queryString = location.search.substring(1), re = /([^&=]+)=([^&]*)/g, m;
while (m = re.exec(queryString)) {
queryParameters[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
queryParameters['Source'] = redirectUrl;
console.log(location.search.replace(location.search,
$.param(queryParameters)));
});
Now I just need to replace the Source query parameter with the new value. How do I do this?