0

With multiple list views on same page, I am trying to add the current page url as &Source= to the new document link. So just looking to pull the current page URL and add it as the &Source to the +new document link. Not sure if I have to encode it or not?

3
  • Ok, got this to work as far as changing the new document link but just need to somehow add the current page url as the variable "&source" at very end of the new url: function changeLink() { $("#idHomePageNewDocument-WPQ6").removeAttr('onclick'); $("#idHomePageNewDocument-WPQ6").attr("href", "#"); $("#idHomePageNewDocument-WPQ6").click(function () { NewItem2(event, "https:….//_layouts/15/Upload.aspx?List=%7b2D0B41F6-84B5-469D-86DC-446215EA47CB%7d&Source="); return false; }); } _spBodyOnLoadFunctionNames.push('changeLink'); – akapital Jul 10 '20 at 18:00
  • This worked: <script src="ajax.googleapis.com/ajax/libs/jquery/1.12.4/…> <script type="text/javascript"> function changeLink() { $("#idHomePageNewDocument-WPQ6").removeAttr('onclick'); $("#idHomePageNewDocument-WPQ6").attr("href", "#"); $("#idHomePageNewDocument-WPQ6").click(function () { NewItem2(event, "https://........ /_layouts/15/Upload.aspx?List=%YourListIdhere%&Source="+encodeURIComponent(window.location.href)); return false; }); } _spBodyOnLoadFunctionNames.push('changeLink'); </script> – akapital Jul 10 '20 at 20:30
  • So I got the script to work but SharePoint still adds the model dialog at the end IsDlg=1, so last step is I just need to remove or override that. The script does not specify it but SharePoint adds it. Will let you know when I figure it out. – akapital Jul 10 '20 at 20:36
0

I wanted to share two approaches that worked for me, depending on whether you want full page non-modal or modal dialog:

  1. As Full Page Non-Modal

$(function () { $("#idHomePageNewDocument-WPQ6").attr("href", "https://SiteName/_layouts/15/Upload.aspx?List={2D0B41F6-84B5-469D-86DC-446215EA47CB}&Source="+encodeURIComponent(window.location.href)); $("#idHomePageNewDocument-WPQ6").attr("onclick", ""); });

  1. As Modal Dialog

function changeLink() { $("#idHomePageNewDocument-WPQ6").removeAttr('onclick'); $("#idHomePageNewDocument-WPQ6").attr("href", "#"); $("#idHomePageNewDocument-WPQ6").click(function () { NewItem2(event, "https://SiteName/_layouts/15/Upload.aspx?List={2D0B41F6-84B5-469D-86DC-446215EA47CB}&Source="+encodeURIComponent(window.location.href)+" "); return false; }); } _spBodyOnLoadFunctionNames.push('changeLink');

Hope this might be helpful to someone else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.