Correct way of generating Source parameter value in your SharePoint Link

As you may already know that SharePoint uses Source parameter in query string to take you back to the page from where you came.

The value of the Source paramter must be properly encoded. Don’t worry, you do not need to write your own Javascript function to do this. Just use already provided function called

GetSource(defaultSource)

It will return you properly encoded string to pass as Source parameter value. Following is the logic inside this function:

  1. Try to retrieve the value Source parameter from current query string.
  2. if Source parameter found then return it by properly encoding and making sure it is safe to navigate.
  3. If there is no Source parameter in Query string then
    • Check if defaultSource has a non empty value,
    • if yes then return it by properly encoding and making sure it is safe to navigate.
    • Otherwise, return the current page url by properly encoding and making sure it is safe to navigate.
Share