Question

I have requirement where client wants to customize the items in quick launch for only certain pages.So, I want to change the items in the quick launch with some other items for a few pages.(Not about cahnging the style of quick launch. Its about the replacingthe content in quick launch)

I hope using CEWP, I can achive this.But I am not much aware how to do it.

Was it helpful?

Solution 2

I had followed following steps to achive the goal

1.. Added a CEWP in the page

  1. Created a text file with Following script and added it to shared dcouments
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <script type="text/javascript">
  function startClock(){

    var div= document.getElementById('s4-leftpanel-content');

   var spans= div.getElementsByTagName('span');

 for (index = spans.length - 1; index >= 0; index--) {
 spans[index].parentNode.removeChild(spans[index]);

 }

 var urls= div.getElementsByTagName('a');  
 for (index = urls.length - 1; index >= 0; index--) {
  urls[index].parentNode.removeChild(urls[index]);
 }

  var pTag = document.createElement('p');
 pTag.innerHTML = "HR Report";
    div.appendChild(pTag);

   var aTag = document.createElement('ul');
   div.appendChild(aTag);

  var newLi = document.createElement('li');
   aTag.appendChild(newLi);

   var a= document.createElement('a');
    a.setAttribute('href',"url");
    a.innerHTML = "report2";
   newLi.appendChild(a);

//do onload work
  }
   if(window.addEventListener){
   window.addEventListener('load',startClock,false); //W3C
    }
    else{
 window.attachEvent('onload',startClock); //IE
}
</script>

enter code here

  1. Paste the url text file in shared documents in CEWP as content link(Edit web part >>content link>>paste url)

Now, existing items in the Quick Launch is removed and new items are added

OTHER TIPS

You can have two approachs here:

1) creating a webpart to replace the quicklaunch: This way you can read the Navigation from SPWeb, and build it your own.

2) Using jQuery to change the html loading the page. In this approach, I would apply a 'display:none' to quicklaunch, make the changes in html, and then 'display:block' back. The con in this solution is that you must rely on the names/titles/urls of the items, so if an admin changes, it could break it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top