Display the Quick Launch in a Web Part page

quicklaunchMost pages on your SharePoint site display a left navigation, also known as “Quick Launch”. However, new Web Part pages that you add through the Create menu do not have it.

So how can we add the Quick Launch to these pages, using only the SharePoint UI? Here again, the iframe can help. On our Web Part page we are going to:
1/ load the site home page in the background
2/ extract the Quick Launch
3/ include it in our page
4/ do some cleanup to avoid conflicts with the rest of the page

This is very similar to the method I described to display a list in another site – just here everything happens within the same site.


Here is the code, simply add it to the page through a CEWP:

<!-- Load and display Quick Launch - iframe version -->
<!-- Questions and comments: Christophe@PathToSharePoint.com -->

<!-- Paste the URL of the source page below: -->
<iframe id="SourcePage" style="display:none;" src="http://[YourSite]/default.aspx" onload="DisplayQuickLaunch()"></iframe>

<script type="text/javascript">

function DisplayQuickLaunch()
{
var placeholder = document.getElementById("LeftNavigationAreaCell");

var quicklaunchmenu = null;
var SourcePage = document.getElementById("SourcePage");

try {
   if(SourcePage.contentDocument)
      // Firefox, Opera

      {quicklaunchmenu = SourcePage.contentDocument.getElementById("LeftNavigationAreaCell") ;}
   else if(SourcePage.contentWindow)
      // Internet Explorer

      {quicklaunchmenu = SourcePage.contentWindow.document.getElementById("LeftNavigationAreaCell") ;}
   else if(SourcePage.document)
      // Others?

      {quicklaunchmenu = SourcePage.document.getElementById("LeftNavigationAreaCell") ;}
}
catch(err) { alert ("Loading failed");}

var allDescendants = quicklaunchmenu.getElementsByTagName("*");
for (i=0;i<allDescendants.length;i++) {
allDescendants[i].removeAttribute("id");
allDescendants[i].removeAttribute("onclick");
allDescendants[i].removeAttribute("onfocus");
allDescendants[i].removeAttribute("onmouseover");
}
placeholder.innerHTML = quicklaunchmenu.innerHTML;
}
</script>

For better performance…

In my code sample, the source page is the home page, but you can actually select any other page from your site that has the Quick Launch. Pick a page with little content for better performance.

Update [05/29/2009] As Cory mentioned in the comments section, here is another approach if you have SharePoint Designer:
http://www.u2u.info/Blogs/Patrick/Lists/Posts/Post.aspx?ID=1744

Advertisements

56 thoughts on “Display the Quick Launch in a Web Part page

  1. robyn, your issue is most likely related to the fact that the quick launch is displayed in an iframe. I have had many of troubles with navigation and frames. I am not sure that christophe script is the problem. Because by default the quick lauch does not reside in frames, that author did not design the script to take that into consideration.

  2. Larry: with this method, the Quick Launch is pulled from the iframe and actually displayed in the page itself (steps 2 and 3 in the post). This is the key difference with other methods that only embed an iframe in the page.

    The current script only keeps the hyperlinks in the transfer, which is enough for a standard Quick Launch. To make it work in Robyn’s case we’ll also need to transfer ids and event handlers. Working on this…

  3. Pingback: Links for February 5, 2009 « Steve Mullen’s Blog

  4. I’m embarrased to admin but want to know what I’m missing in the 4 steps. Is IFrame something that my WSS3.0 already has installed or do I need to get that before this code will do anything?

    Oh, and Blank Stare on my part to the 2nd item “extract the Quick Launch”.

    I’m honestly not slaming anyone and mean this as a complement; but you guys are so frigen smart and have forgotten what it’s like to be learning something for the first time. But I did use your Calendar Code and absolutely love my tiny calendar. I’ve wanted that for years.

    Thank you.

  5. Hi Mike,

    I have to admit that I was very concise on this post (what a nice way to put it 😉 )

    However, please understand that a post has limited space, and I can’t go all the way from the basics to the original solution I propose.

    For example, when I talk about the CEWP, I just link back to another post that provides more details. For concepts that are not even SharePoint specific, like the iframe, you’ll need to turn to HTML tutorials, like w3schools:
    http://www.w3schools.com/

    The nice part is that I provide ready to use samples. So you can start using the solution now and understand it later.

    That’s how I started myself…

  6. Thanks – great post

    One question – how do I get rid of the breadcrumb trail in the page that points back to the source library/item that is being displayed?

    Thanks

    • Hi Owen,

      I have been going through most of the CEWPs in your link below as I am keen on removing the library reference in my breadcrumb (not the whole breadcrumb), but cannot find the “hide references” one you are referring to.

      Also the above source code worked like a charm, but I must be doing something wrong with the implementation of the others as I am constantly getting the error message “cannot import”.

      Would you mind lending me a hand by:
      – giving me the exact name of the CEWP that you have used for the breadcrumb
      – and advising me where you had to modify the code (if necessary) for it to work?

      Thank you so much & best regards,

      Vivian

      • Hi,

        Just figured out what I was doing wrong – I was copying the full code which is probably intended for the sharepoint design users. I am afraid that I am restricted to purely the GUI and therefore it works only for me when inserting the … area (in case anybody has the same dopey brainwave at me and is trying to work out why it doesn’t work ;))

        My question still stays open though as far as the request for a CEWP that removes the document library from the breadcrumb. At the moment I only found CEWPs that remove the entire breadcrumb.

        Thanks for all help that you guys can give me & best regards,

        Vivian

  7. I know that you specify “using only the SharePoint UI”, but I think it’s important to point out that the Quick Launch menu *IS* actually present on a web part page. The page layout for the default web part pages you create in SharePoint override the default ContentPlaceHolders from the master page – you just need to remove those empty ContentPlaceHolders. It’s a quick and easy modification in SharePoint Designer – no need to use iFrames, and those flyout menu options will now work without any messy transfer IDs and event handlers.

    Here are the content placeholders I delete:

    PlaceHolderLeftActions
    PlaceHolderPageDescription
    PlaceHolderBodyRightMargin
    PlaceHolderPageImage
    PlaceHolderLeftNavBar
    PlaceHolderNavSpacer

  8. Cory: yes, I specified “only using the SharePoint UI”. I know that times are changing, but this post was written at a time when SPD was not free. Even today, many users don’t have the right to use it in their environment.

    And even if allowed, unghosting pages just to add a couple Quicklaunch bars is not necessarily the best option. So my point of view is: it’s an easy iframe/CEWP, no need to use SPD.
    That said, people should be aware of the SPD option, so I’ll add a link to a post that explains it.

    Thanks for alerting me on messy ids and event handlers, I’ll take a closer look. Maybe I actually need to remove them, like I did in other scripts.

  9. Hi,
    I hwave two questions:

    1. I’d like to know if there’s a way to assign a link to a document library using stsadmin?
    2. I’d like to know if there’s a way to add a document library webpart to a site using stsadmin?

    I am running WSS 3.0.

    Any assistence will be appreciated.

    Thanks,
    Fuad

  10. Cristophe, thank you very much for the solution on how to get the left-hand nav appearing on a web part page – I am still clueless why they would have decided to not have that appear in the first place!?!? But this works like a charm, so thanks!

    One thing I have noticed though is that it seems to be pushing my left-hand nav downwards, i.e. it’s no longer beginning at the top. The space that is inserted in the left-hand nav is the height of the breadcrumb and the page title of the content page. Is there any way to get the left-hand nav to start at the top of the column?

    Thanks in advance & best regards,

    Vivian

  11. Hi ,
    i have customized the quick launch by modifying the code in the default.master page using sharepoint designer 2007. after that only the list item are collapsed but i am not able to view the sub contents in a list item in quick launch.. how can i view the sub links under quick launch..expecting ur reply asap.

    thanks
    sandesh

  12. Pingback: Display the Quick Launch in a Web Part page « Path to SharePoint | Intenseblog.com

  13. I copied the url into the code but it did absolutely nothing to
    the page. Is there something else I am supposed to modify?

  14. For some reason, one line of the code was not displayed. It should be ok now.
    Isaac, you need to copy your URL in the src attribute of the iframe.

  15. Thanks for the great script to have Quick Launch appear on Web Part pages.
    On my default page with the Quick Launch I have applied script for the Quick Launch to appear in Accordian format. http://www.endusersharepoint.com/2008/12/03/jquery-for-everyone-accordion-left-nav/
    However, on the Web Part pages using your script the Quick Launch will not expand from Accordian format. I have tried to apply the Accordian script to the Web Part page but that makes no difference.
    Is it possible to adapt the script used to have Quick Launch appear on Web Part pages to accept the script for Accordian ??

    • Carol, how did you chain the two scripts? I would expect this to work, but you need to call the accordion script only after the DisplayQuickLaunch script has finished running.

  16. Hi Christophe, Thanks for your response.
    The Accordion script is a CEWP on the default page for the site.
    Then I’ve created a new Web Part page using the Display Quick launch as a CEWP. On this page the Quick launch does appear in the accordian format (as on the default page) but it will not expand the Quick launch, the arrows appear but won’t expand. On the default page, the expand/collaspe works fine.

  17. It is the default page I reference in the Display Quick launch script.
    Not sure if there is another way I should be launching the scripts ??

    • First, you can try this: in my script, remove line 35:
      allDescendants[i].removeAttribute(“onclick”);
      Hopefully this will avoid the deactivation of the accordion.

      If not, then the solution will be more involved. You’ll need to go into the code and combine both scripts.

  18. Hi,
    I tried removed the line of code you suggested. It has not fixed the problem. The accordian Quick launch will still not expand.
    When you suggest to combine both scripts, is it as simple as ‘copy / paste’ the 2 scripts in the one CEWP 🙂 (you’ll guess I’m not a jquery programmer) … when combining the scripts, I assume the combined version would need to be applied on both the default page where the Quick launch appears normally and then then the new Web Part page

  19. I am having some difficulties getting the Quick Launch to display on the sub-level pages of my site. I have the Quick Launch menu hidden on the default.aspx home page. I have added a CEWP to my sub-leve layout page – added the script provided in your article above and changed the SRC to point to the home page of the site collection, http://newer.corptax.com/pages/default.aspx – and updated the navigation settings (on the About Us section only) to show sub sites and sub pages, but nothing is displaying. No error, just no menu either.

    Could you take a look to tell me if I missed something? This is critical to the design specifications to have the quick launch showing on these sub pages.

    Thanks in advance for any assistance you can provide.

    • The above script works on Web Part pages. In your case, you are using a different template (html page?), and the script cannot find the placeholder (“LeftNavigationAreaCell”).

      • I am using a custom layout page. I assumed this would work for any layout page. On my custom master page the left navigation is nested inside the placeholder named PlaceHolderLeftNavBar. Would I replace LeftNavigationAreaCell with this? Or are you saying that this code won’t work except on a web part page? Thanks for the help! I am dying here.

  20. Your solution works great, thank you!
    The only issue I have is when putting on a sub-site, the View All Site Content and the Recycle Bin point to the Parent site’s all content and recycle bin. Any suggestions on how to get these two to point to the current site’s areas?

    • Well, that’s the expected behavior, as you chose to display the menu from the parent site. You would need to add some post-processing, to modify the path in the links. Re-building the sub-site menu might be easier.

  21. Pingback: WebPart page in Quick Launch | amavs

  22. Pingback: Display the Quick Launch in SharePoint - Websphere Tutorial

  23. Pingback: Display Quick Launch On A Web Part Page Using Content Editor Web Part « Rain Tree Studio's Blog

  24. Tried this in SP2010 and it does not seem to work. Would be very greateful for a 2010 version of this. Nice work!

  25. Here’s the code for SharePoint 2010



    http://../default.aspx

    <script type="text/javascript">
    
    function DisplayQuickLaunch()
    {
    var placeholder = document.getElementById("s4-leftpanel-content");
    
    var quicklaunchmenu = null;
    var SourcePage = document.getElementById("SourcePage");
    
    try {
       if(SourcePage.contentDocument)
          // Firefox, Opera
    
          {quicklaunchmenu = SourcePage.contentDocument.getElementById("s4-leftpanel-content") ;}
       else if(SourcePage.contentWindow)
          // Internet Explorer
    
          {quicklaunchmenu = SourcePage.contentWindow.document.getElementById("s4-leftpanel-content") ;}
       else if(SourcePage.document)
          // Others?
    
          {quicklaunchmenu = SourcePage.document.getElementById("s4-leftpanel-content") ;}
    }
    catch(err) { alert ("Loading failed");}
    
    var allDescendants = quicklaunchmenu.getElementsByTagName("*");
    for (i=0;i<allDescendants.length;i++) {
    allDescendants[i].removeAttribute("id");
    allDescendants[i].removeAttribute("onclick");
    allDescendants[i].removeAttribute("onfocus");
    allDescendants[i].removeAttribute("onmouseover");
    }
    placeholder.innerHTML = quicklaunchmenu.innerHTML;
    }
    </script>
    
  26. Oops sorry misposted … Here’s the full code …

    <!-- Load and display Quick Launch - iframe version -->
    <!-- Questions and comments: Christophe@PathToSharePoint.com -->
    
    <!-- Paste the URL of the source page below: -->
    <iframe id="SourcePage" style="display:none;" src="../default.aspx" onload="DisplayQuickLaunch()"></iframe>
    
    
    <script type="text/javascript">
    
    function DisplayQuickLaunch()
    {
    var placeholder = document.getElementById("s4-leftpanel-content");
    
    var quicklaunchmenu = null;
    var SourcePage = document.getElementById("SourcePage");
    
    try {
       if(SourcePage.contentDocument)
          // Firefox, Opera
    
          {quicklaunchmenu = SourcePage.contentDocument.getElementById("s4-leftpanel-content") ;}
       else if(SourcePage.contentWindow)
          // Internet Explorer
    
          {quicklaunchmenu = SourcePage.contentWindow.document.getElementById("s4-leftpanel-content") ;}
       else if(SourcePage.document)
          // Others?
    
          {quicklaunchmenu = SourcePage.document.getElementById("s4-leftpanel-content") ;}
    }
    catch(err) { alert ("Loading failed");}
    
    var allDescendants = quicklaunchmenu.getElementsByTagName("*");
    for (i=0;i<allDescendants.length;i++) {
    allDescendants[i].removeAttribute("id");
    allDescendants[i].removeAttribute("onclick");
    allDescendants[i].removeAttribute("onfocus");
    allDescendants[i].removeAttribute("onmouseover");
    }
    placeholder.innerHTML = quicklaunchmenu.innerHTML;
    }
    </script>
    
      • Christophe,

        I couldn’t get this code to work with SharePoint 2010. However, I got the following to work:

        function DisplayQuickLaunch()
        {
        var placeholder = document.getElementById(“s4-leftpanel-content”);

        var quicklaunchmenu = null;
        var SourcePage = document.getElementById(“SourcePage”);

        try {
        if(SourcePage.contentDocument)
        { quicklaunchmenu = SourcePage.contentDocument.getElementById(“s4-leftpanel-content”); }
        else if(SourcePage.contentWindow)
        { quicklaunchmenu = SourcePage.contentWindow.document.getElementById(“s4-leftpanel-content”); }
        else if(SourcePage.document)
        { quicklaunchmenu = SourcePage.document.getElementById(“s4-leftpanel-content”); }
        }
        catch(err) { alert(“Loading failed”); }

        var allDescendants = quicklaunchmenu.getElementsByTagName(“*”);
        for (i=0;i<allDescendants.length;i++) {
        allDescendants[i].removeAttribute("id");
        allDescendants[i].removeAttribute("onclick");
        allDescendants[i].removeAttribute("onfocus");
        allDescendants[i].removeAttribute("onmouseover");
        }
        placeholder.innerHTML = quicklaunchmenu.innerHTML;
        }

        jQuery(document).ready(function() {
        jQuery(‘#s4-leftpanel’).attr(‘style’,’display: block !important’);
        jQuery(‘#MSO_ContentTable’).attr(‘style’,’margin-left: 155px !important’);
        });

  27. Sorry about my prior comment,- some of my code got truncated. Try (after removing the beginning and ending comments):

    <!–

    function DisplayQuickLaunch()
    {
    var placeholder = document.getElementById(“s4-leftpanel-content”);

    var quicklaunchmenu = null;
    var SourcePage = document.getElementById(“SourcePage”);

    try {
    if(SourcePage.contentDocument)
    { quicklaunchmenu = SourcePage.contentDocument.getElementById(“s4-leftpanel-content”); }
    else if(SourcePage.contentWindow)
    { quicklaunchmenu = SourcePage.contentWindow.document.getElementById(“s4-leftpanel-content”); }
    else if(SourcePage.document)
    { quicklaunchmenu = SourcePage.document.getElementById(“s4-leftpanel-content”); }
    }
    catch(err) { alert(“Loading failed”); }

    var allDescendants = quicklaunchmenu.getElementsByTagName(“*”);
    for (i=0;i<allDescendants.length;i++) {
    allDescendants[i].removeAttribute("id");
    allDescendants[i].removeAttribute("onclick");
    allDescendants[i].removeAttribute("onfocus");
    allDescendants[i].removeAttribute("onmouseover");
    }
    placeholder.innerHTML = quicklaunchmenu.innerHTML;
    }

    jQuery(document).ready(function() {
    jQuery(‘#s4-leftpanel’).attr(‘style’,’display: block !important’);
    jQuery(‘#MSO_ContentTable’).attr(‘style’,’margin-left: 155px !important’);
    });

    –>

Comments are closed.