SharePoint 2013:在按下取消按钮后重定向到不同的页面

时间:2017-05-23 19:44:31

标签: javascript jquery sharepoint

我正在使用SharePoint 2013.我有一个反馈和建议的自定义列表表单。目前,要访问表单,用户单击链接会将其直接转到“新项目”表单。

我想要完成的事情:    - 当用户单击“保存”时,会将其转到“感谢您”页面。    - 当用户点击取消时,它们将被带回主页。

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

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

我唯一可以编辑表单的是添加代码段。

提前致谢!

2 个答案:

答案 0 :(得分:0)

为此,我做了以下事情:

按下“保存”按钮后重定向:

  1. 创建一个Thank You页面并复制URL。稍后再保存。
  2. 添加"?source ="然后是从第1步到链接结尾的网址,它会将您带到新的商品页面。 EX:https://NewItemForm.aspx?Source=https://ThankYou.aspx
  3. 如果您点击保存或取消,那将重定向到感谢页面。

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

    1. 转到您的清单>表格Web部件(在功能区中)>默认新表格
    2. 插入脚本编辑器Web部件
    3. 添加以下代码:
    4. 
      
      <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>
      &#13;
      &#13;
      &#13;

      这将删除功能区中的上方取消按钮,并使表单上的取消按钮返回到goToByePage功能中列出的任何页面。

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

      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

      希望将来帮助其他人!

答案 1 :(得分:0)

SharePoint 开箱即用的行为是将用户发送到源查询字符串参数中的 url,当他们单击新表单上的保存按钮或取消按钮时。

由于 OP 正在经历不同的行为,因此可能(甚至可能)有人已将代码添加到她网站的母版页以覆盖 oob 行为。

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