Hi All,
we have one list and we are using out of box form to save the item into SharePoint list now after save button click we need to redirect into another page (Home.aspx) page and I have tried following approaches but now working as expected.
Approach-1 :Redirect using window.location.href = "NewPageURL";
Approach-2 : Use below JavaScript code to redirect on "ok" button click.
if(window.confirm=="You data save successfully")
{
window.location.href = "NewPageURL";
}
Approach -3 User below java scrip code to replace the source URLto new post back URL
Note : Using below alert is showing getitng properly but page is not redirection to home.aspx page.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('input[value=Save]').click(function() {
if (!PreSaveItem())
{
return false;
}
else
{
validation();
}
});
});
function validation()
{
var spanlength = $('.ms-formvalidation').find('span').length;
if(spanlength == 0)
{
var elementName;
var oldPostbackUrl;
var currentSourceValue;
var newPostbackUrl;
var button = $("input[id$=SaveItem]");
//change redirection behavior
button.removeAttr("onclick");
button.click(function() {
var elementName = $(this).attr("name");
var aspForm = $("form[id=aspnetForm]");
oldPostbackUrl = aspForm[0].action;
currentSourceValue = GetUrlKeyValue("Source", true,
oldPostbackUrl);
newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "/sites/DEV/sitecollecton/siteName/SitePages/Home.aspx");
if (!PreSaveItem())return false;
}); //end button.click
alert("submitted !! ");
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
}
}
</script>
Any help would be highly appreciated !!
Thanks & Regards
Deepak Chauhan
SharePoint 2010 & 2013 and Office-365 Branding and Front End Customization, UI Design