So I have my document libraries set up with an extra button using the following jQuery script:


function ButtonFunc() {
   $('.ms-qcb-leftzone').append('<li class="ms-qcb-item"><a href="http://www.google.com">All Docs</a></li>');

As you can see the button is just a link to google. How can I set the button to be a link to a specific view of the document library?

For example, if I have a document library and I click on this button I added, I want the link to take you into the document library and be able to specify a view. Since the jQuery runs on all of the pages in my site (i put a scriptlink to the Jquery code in my master) I want it to work for each document library without having to put in a specific URL.

1 Answer 1


This is not easy as you think. Following are the steps you can try

  1. Create an array and store the list of document libraries and their default view URL. You can use JSOM to get this information.
  2. On each page load check the URL and see if the URL exists on the Array
  3. If exists then execute your script to create dynamic button on the ribbon.
  • what about something where you can grab the name of the document library based on the doclib the button is in? May 20, 2016 at 17:19
  • The doclib button is a JavaScript hack.. May 20, 2016 at 17:29
  • by my understanding the code i wrote is a combo of jquery and JS. What does that have to do with being a JS hack? May 20, 2016 at 19:00
  • Ideal way of adding new ribbon items is via custom actions. May 21, 2016 at 3:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.