Category Archives: Javascript

The Source parameter and the difference between GoToPage and GoToLink

A very convenient URL parameter in SharePoint is the Source parameter. If you click on an item in a list for example, you’ll notice this Source parameter in the URL (e.g. /Lists/Projects/DispForm.aspx?ID=31&Source=http%3A%2F%2Fdev-server%2Fcorporate%2FLists%2FProjects%2FAllItems%2Easpx) Now when you click the Close button, you are redirected to the page where you came from. Of course this is also possible with a history.back() call, but there are situations when this won’t work. For example, what if you have custom columns on your NewForm.aspx that require a postback? So the Source parameter is a very neat feature to redirect a user to where he/she came from.

In DataView web parts, you might want to create your own dynamic URLs (inserting parameters from the Data Source into your URL), and have the user redirected back to the page with the DataView web part instead of the SharePoint list where the item was created. For example, we have a customer site for each of our customers. From the home page of such a site, we’d like to create a new item in a Projects list (which is located at a site higher in the hierarchy). Next when the user clicks the OK button, the user should be redirected back to the customer site. We can do this by manually adding the Source parameter to the URL:

(as a side note, you can also use the NewItem Javascript function for creating new list items, but this is beyond the scope of this article)

But what if the Source URL is actually also a dynamic URL, with some own parameters (like ID= and List= in a Workflow Task Form)? Javascript to the rescue! SharePoint comes with two great Javascript functions: GoToPage and GoToLink, which add the Source parameter to a URL automatically. I’ll discuss the difference between these two in a minute. Let’s change the URL XSLT example above to include the GoToLink function:

With this format, we can use this XSLT for example on a Workflow Task Form, from where the user can click the link, fills out the project details, clicks OK, returns to the Workflow Task Form, and completes the task.

 

So what about the difference between the GoToPage and GoToLink functions? Both functions are available in SharePoint pages. Both functions seem to do exactly the same, but there are some differences.

First, there is the location of the functions. The GoToPage function is available from the INIT.JS libray, the GoToLink function comes from the CORE.JS library.

Next, there is a slight difference in functionality. Let me first show both functions (the GoToPage function calls another function, called STSNavigate, so I’ll show this function as well, where the GoToLink function does exactly the same on its own):

GoToPage

GoToLink

Now, what we notice, is the GoToPage function expects a full URL as input, where the GoToLink function reads the href tag of the element. So in the GoToLink function you can use this as parameter, taking the value of the href tag as input parameter. Less error prone, and easier to maintain. But in the GoToPage function, you can use another URL in the href tag, than in the actual Javascript parameter. So you can show a different URL in the status bar of the user’s browser, than the actual URL the user is redirected to. Also quite nice in some occasions!