1

Is there any way I can make the top links on the nav bar inactive? Basically I have created sites under the root such as

Company Info
HR
Team 1
Team 2....

and under each of those there are sub sites which show up in the drop down.

I want the top links

Company Info
HR
Team 1
Team 2....

to be inactive. So if a user clicks them they dont navigate to the site, can this be done? I would be ok with changing the link so it would just link back to the home page, but where would I change that?

Thanks for any help!

5 Answers 5

2

Yes, you can do it. Use this:

$("body #s4-topheader2. ul li ul li.static > a").each(function(index) {

if(index!=2)
{

    $(this).attr("href","javascript:void(0);");
}

});

Cheers !

2
  • you are the man! Thank you! thats exactly what I needed.
    – Tudor
    Commented Jul 31, 2012 at 15:38
  • Pleasure to be helpful :)
    – J.Shah
    Commented Aug 1, 2012 at 9:31
0

I tested this line of jQuery against a SP2010 page running the v4.master

$().ready(function(){
 $(".menu-horizontal").find("a").removeAttr("href");
});

Put this right on the master page, or hook it up to a CustomAction to load this all over the site.

Be aware that certain features in SharePoint(like Publishing Infrastructure, for example) alter the DOM a little so you may have to F12 this if it doesn't work at first.

4
  • doesn't seem to work for me...I added this to my master page <head> <script type="text/javascript"> $().ready(function(){ $(".menu-horizontal").find("a").removeAttr("href"); }); </script> I am using the Publishing Infrastructure, is that the issue?
    – Tudor
    Commented Jul 26, 2012 at 20:21
  • I forgot to mention, I tried replacing .menu-horizontal with a number of different tags including .s4-tn and I can't seem to get it working.
    – Tudor
    Commented Jul 26, 2012 at 20:36
  • Is jquery included? If it isn't then the script won't do anything. Commented Jul 27, 2012 at 0:00
  • Thanks! it works! however its not quite what I need, that basically disables the links that show up in the drop down under the main headings, is there a way to only disable the top links and not the ones in the dropdown?
    – Tudor
    Commented Jul 27, 2012 at 16:20
0

I was having same requirement. and this works for me.

$(document).ready(function() {

     $("body #s4-topheader2. ul li ul li a").attr("href","javascript:void(0);");
});

May be it helps you.

Don't forget to include JQuery in your master page.

1
  • Thanks! it works! however its not quite what I need, that basically disables the links that show up in the drop down under the main headings, is there a way to only disable the top links and not the ones in the dropdown?
    – Tudor
    Commented Jul 27, 2012 at 16:20
0

Would putting the following in the header work?

<script type="text/javascript">
$("body #TopNavigationMenuV4. ul li ul li.static > a").each(function(index) {
if(index!=2) {
$(this).attr("href","javascript:void(0);");
}
});
</script>

I couldn't get this working at all...

1
  • where do you put this code, in a script web part on the page?
    – raj
    Commented Oct 30, 2017 at 11:58
0

I think this will helps you to get your requirements:

$("body #s4-topheader2. ul li ul li.static > a").attr("href","javascript:void(0);");
1
  • awesome! thank you! that works perfectly, is there any way to activate just the first link? For example one of the web apps we have has a home link, can I have just that link active and not the rest?
    – Tudor
    Commented Jul 30, 2012 at 17:23

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.