No More SharePoint Quick Launch Links That Fail

June 14, 2012 by

The Problem

We at BrightWork regularly build project management templates in SharePoint and we always use the Quick Launch to help clarify the process sequence. As templates, they then get copied over and over again, to create new SharePoint Project sites, and the Quick Launch gets re-used throughout. This works great!

However, you might (for example) decide to copy or move your site collection, effectively changing the relative URL of the sites and potentially breaking the links in some Quick Launches. The good news is that not all links in the Quick Launch links are at risk of breaking, any ‘internal’ links i.e. links you cannot edit the URL value of, will transfer without issue. Here is a screenshot of an ‘internal’ Quick Launch link.

However, external links, i.e. links with URLs that are editable, are likely to no longer work if the site relative URL changes. So, in this example, if a site collection changes from ‘pmpoint’ to ‘BrightWork’ the link below in the screenshot will not change with it and therefore will generate an error when clicked (or worse, bring you somewhere you do not want to go to).

The Solution

A way to work around this issue is to replace the URL used with some JavaScript [which is not as difficult as it might sound]. Here are some simple worked examples to get you started.

First though, it is worth knowing what L_Menu_BaseUrl is, as it is used everywhere below. L_Menu_BaseUrl is quite simply a way in JavaScript to get the URL of the current site. It is a SharePoint JavaScript Variable meaning it is available throughout the site … and is as useful as a small pot!

Example 1: Create a link to the ‘Project Home’ page of a site

  1. Open the Site SettingsQuick launch page, add a New Heading
  2. Paste in the following line into the Type the Web addressfield:
    javascript:window.open(L_Menu_BaseUrl,'_self');void(0);
  3. Enter a value for Type the description: e.g. Project Home
  4. Click Ok to save
  5. Select Change Order to make this the first item in the Quick Launch and you now have a link to the default page of the SharePoint Project site

How It Works

Command ElementTells SharePoint …
javascript:that what is to follow is JavaScript
window.open(to open a URL
L_Menu_BaseUrl,the URL to open is the URL of the current site
‘_self’);to open the URL in the same window
You can leave out the ,’_self’ to open in a new window every time
void(0);not to reload the current page which is needed to avoid any errors!

Example 2: Create a link to the SharePoint Project site’s parent site

  1. Repeat the steps in Example 1 and create a New Headingand add the following URL:
    javascript:window.open(L_Menu_BaseUrl.substring(0,L_Menu_BaseUrl.lastIndexOf('/')),'_self');void(0);
  2. Enter a value in the Type the Description field e.g. ▲Up a Level and click OK.
  3. Use Change Order to re-order the links as before

Note: The JavaScript used here removes the last portion of the URL i.e. everything after the last forward slash (/), leaving the URL to the parent site.

For example, a URL like:
/sites/brightwork/projects/finance/2011YearEnd
… becomes:
/sites/brightwork/projects/finance

Example 3: Create a link to a View in a List

  1. First get the URL address of the view from your browser address bar. Paste it into Notepad (or something similar)
  2. Next, remove the site specific part of the URL, just keeping the end portion of the URL. The end portion should be something like:
    /Lists/Project%20Tasks/active.aspx

    For example, a URL like:
    https://www.brightworkdemo.com/sites/pmpoint/Contoso/c2010mp/projlite/Lists/Project%20Tasks/active.aspx

    … becomes:
    /Lists/Project%20Tasks/active.aspx

  3. This time we want to add a standard New Navigation Link, so follow the steps in Example 1 selecting New Navigation Link as opposed to New Heading
  4. Using this piece of JavaScript and replacing the red text in single quotes with the ‘/lists/etc.‘ portion of the URL, add this as the web address:
javascript:window.open(L_Menu_BaseUrl+'/Lists/LISTNAME/VIEWNAME.aspx','_self');void(0);
For example:

Note: if someone deletes this view the URL will no longer be valid. It would therefore be recommended that you use the list name in the Quick Launch as opposed to a specific view so that the default view will open automatically.

Example 4: Create a link to a web part page in a library

  1. As with Example 3, get the URL of the web part page you want to link to and remove the site details from the URL by editing it in Notepad

    For example, a URL like:
    https://www.brightworkdemo.com/sites/pmpoint/Contoso/c2010mp/projlite/BrightWork%20Pages/Project%20-%20Dashboard.aspx
    … becomes:
    /BrightWork%20Pages/Project%20-%20Dashboard.aspx

  2. Again, as with Example 3, add replace the red text with the end portion of the URL and add it as a Quick Launch link

     

The Caveats

There is always something and thanks to Mike Smith for writing about this one previously! Adding JavaScript to a Quick Launch for a Published SharePoint site is not permitted.

Also, it is not possible to open these links in a new tab or new window because we are explicitly telling SharePoint not to so that.

In Summary

So, above are some fairly straight forward ways to create robust Quick Launch links. This approach will be overkill for many simple scenarios, but if you want to create bulletproof templates with links that are not going to fail when the relative site URL changes then this should be part of your build process.

Image credit

Fintan Manning

VP Engineering, BrightWork
Fintan Manning

Latest posts by Fintan Manning (see all)

    Pin It on Pinterest

    Share This