Correct way of generating Source parameter value in your SharePoint Link

By Namwar Rizvi - Last updated: Tuesday, February 21, 2012 - Save & Share - Leave a Comment

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
Posted in How To, Information, JavaScript • Tags: , , , , , , Top Of Page

Write a comment