SharePoint 2013:点击取消按钮后重定向到其他页面



我正在使用SharePoint 2013。我有一个用于反馈和建议的自定义列表表单。目前,要访问表单,用户单击一个链接,该链接将他们直接带到"新建项目"表单。

我正在努力完成什么: - 当用户单击保存时,他们将被带到"谢谢"页面。 - 当用户单击"取消"时,将返回到主页。

我做过的事情: - 在新表单的链接上,我添加了"?source=(感谢页面的 URL" - 这完成了"保存"按钮任务,但没有完成"取消"按钮任务。

我需要帮助: 我需要知道如何覆盖默认的取消按钮。现在,它还重定向到"谢谢"页面。我需要它去主页。

我唯一能做的编辑表单就是添加代码片段。

提前感谢!

SharePoint 开箱即用的行为是在用户单击新窗体上的"保存"按钮或"取消"按钮时将用户发送到"源查询字符串"参数中的 URL。

由于 OP 遇到不同的行为,因此可能(甚至可能)有人向其网站的母版页添加了代码以覆盖 oob 行为。

任何来这里寻找如何重定向取消按钮的人,请在花费数小时寻找一些深奥的解决方案(如我的用户之一)之前检查您自己网站中的行为。我向他展示了如何使用 source 参数,我们在 <1 分钟内解决了他的问题。

为此,我做了以下工作:

要在按下"保存"按钮后重定向:

  1. 创建"感谢"页面并复制 URL。保存以备后用。
  2. 添加
  3. "?source=",然后添加步骤 1 到链接末尾的 URL,该链接将您带到新项目页面。 如:https://NewItemForm.aspx?Source=https://ThankYou.aspx

如果您点击保存或取消,这将重定向到"谢谢"页面。

要修复"取消"按钮,请同时执行以下操作:

  1. 转到列表>表单 Web 部件(在功能区中)>默认新表单
  2. 插入脚本编辑器 Web 部件
  3. 添加以下代码:

<script>
function goToByePage(){
window.location.assign("https://SitePages/Home.aspx");
}
function overrideCancel()
{
	//Custom input button
	var input = document.createElement('input');
	input.type = "button";
	input.name = "Cancel";
	input.value = "Cancel";
	input.id = "custominput";
	document.querySelectorAll('.ms-toolbar input[value=Cancel]')[1].parentNode.appendChild(input);
	document.getElementById("custominput").setAttribute("class", "ms-ButtonHeightWidth");
	
	//Hiding already implemented cancel buttons
	document.querySelectorAll('.ms-toolbar input[value=Cancel]')[0].style.display = "none";
	document.querySelectorAll('.ms-toolbar input[value=Cancel]')[1].style.display = "none";
	
	//this is main logic to move history back
	document.getElementById("custominput").setAttribute("onclick", "goToByePage();");
}
_spBodyOnLoadFunctionNames.push('overrideCancel');
</script>
<style>
#Ribbon.ListForm.Edit.Commit.Cancel-Large
{
	display:none;
}
</style>

这将删除功能区中的上部取消按钮,并使表单上的取消按钮将您带回goToByePage函数中列出的任何页面。

此代码来自 2 个不同的来源:

https://sharepoint.stackexchange.com/questions/190776/basic-custom-list-how-to-redirect-to-different-page-on-cancel-and-on-save-butto

https://social.msdn.microsoft.com/Forums/office/en-US/5036ab40-2d9b-4fe5-87a2-5805268eea07/how-to-override-behavior-of-the-cancel-button-in-the-ribbon-and-the-form?forum=sharepointdevelopment

希望这对将来的其他人有所帮助!

最新更新