Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top