Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Say I have a page that is really long, with marked Headers 1,2,3, etc. Would it be possible to create a webpart that will auto-generate the table of contents, based on the marked headers and put it in a column to the right?

I know that the webpart has a table of contents, but that only takes the whole site instead of a specific page. Any help greatly appreciated! :)

share|improve this question

1 Answer 1

This could be done with jQuery in an hour or two with properly defined content. You would need to identify a unique place in the document to generate the ToC as well as be able to identify the headers to be included. jQuery could even add Anchors in the content to allow for hyperlinks directly to the sections.

The actual syntax would vary depending on your structure and needs but basically you would use jQuery/javascript to grab the ToC Container, then use jQuery to search the rest of the page for the Header Text to be included and then dynamically build that list and write it into ToC Container as HTML. It would probably look something like this:

jQuery(".ClassOfHeaderText").each(function() {
   /// build new ToC Html with title / links
   newToCHtml += "<li>" + jQuery(this).text() + "</li>"
});

jQuery("#IDOrClassOfToCContainer").html(newToCHtml)
share|improve this answer
1  
Could you even put that into reusable content field? Might be more straightforward for content editors if it would work from there. –  Jussi Palo Feb 27 '13 at 20:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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