0

Goal: Hyperlink goes to/makes active specified easytab tabbed web part on page

I've been going round & round, experimenting w/differing easy tabs scripts & scripts to make linking to a specific tab possible, but w/o success. Can someone help?

Current easy tabs (works well itself. Loaded js file to document library, linked it to page w/content editor): http://usermanagedsolutions.com/sharepoint-user-toolkit/Pages/Easy-Tabs-v5.aspx

Nav script on page (tried a few, here's 2):

1) script

var url = document.location.toString(); if (url.match('#')) { $('.nav-tabs a[href=#'+url.split('#')[1]+']').tab('show') ; }

// Change hash for page-reload $('.nav-tabs a').on('shown.bs.tab', function (e) { window.location.hash = e.target.hash; })

2) text/javascript

    jQuery(document).ready(function() {
        var hash = document.location.hash;
        var prefix = "tab_";
        if (hash) {
            var tab = jQuery(hash.replace(prefix,"")).attr('href');
            jQuery('.nav-tabs a[href='+tab+']').tab('show');
        }
    });

Link format used to try to link to/activate specified tab

--used F12 to find web part title ID. This example was the 2nd tab's ID

end part of link tried:

Pages/leaselinks.aspx#tab-etWPQ4

Pages/leaselinks.aspx#tab_etWPQ4

Pages/leaselinks.aspx#etWPQ4

Pages/leaselinks.aspx/#tab_etWPQ4

Can you tell what is missing or wrong?

  • FWIW. I used to use that solution, but started going with JQueryui.com. (jqueryui.com/tabs). They have customizable solutions that you can cut and paste into SharePoint. I download the CSS and JS files locally and tweak the html to meet my needs. I use the tabs and accordion. Easy to use. – David Jenkins Oct 4 '16 at 17:49
  • TY David. Excuse my ignorance, but I came across that pg b4, but don't understand how that translates to tabbing webparts? Handy for potential typed-in/text tabs but how to make them function the same? – LAH Oct 4 '16 at 18:34
  • Sorry. I missed that one line. Shame. ;) – David Jenkins Oct 4 '16 at 20:22
  • So Mark Rackleys solution is not what you are looking for? markrackley.net/2015/08/16/… – Kasper Bo Larsen Mar 21 '18 at 6:44
1

Updated... How it should work...

After selecting a tab it changed the hyperlink like so:

Original: https://mysite/leaselinks.aspx

Tab: https://mysite/leaselinks.aspx#tab_etWPQ4

Then I can use the hyperlink ending in #tab_ to direct users to the page and activate that specific tab.

This will work on occasion, guessing due to cookies, but not as an actual solution.

The EasyTabs script I am using is Chris Humbert's, plus script to adjust tab color at top I think I got from another source

(add brackets style type="text/css" at top and close script at bottom)

 
.et-tab{font-size:11pt;font-weight:bold;padding:3px 10px;background:url("/_layouts/images/selbg.png") repeat-x;display:inline-block;cursor:pointer;}
.et-activetab{background-color:#cccccc;border:solid 1px #cccccc;color:#003865;}
.et-inactivetab{background-color:#003865;border:solid 1px #003865;color:#ffffff;}
.et-separator{height:5px;background-color:#cccccc;}
.et-tabrow{white-space:nowrap;}
.et-offscreen{position:absolute;max-height:1px;max-width:1px;top:-9999px;}

/* Easy Tabs v 5.0 * Copyright (c) 2009-2010 Christophe Humbert * http://www.pathtosharepoint.com / / Easy Tabs v 5.0 * Copyright (c) 2009-2010 Christophe Humbert * http://www.pathtosharepoint.com */ (function(){ var AP="",sec=0,Header="none",Split="No",Expand="",Print=""; if (document.forms[0].elements["_wikiPageMode.value"]=="true"||document.forms[0].elements["MSOLayout_InDesignMode"].value=="1"){
return;
} var el=document.getElementsByTagName("SCRIPT"),p=el[el.length-1],sT,a,sep,tabRow; do { p=p.parentNode; sT=p.innerHTML.split("MSOZoneCell_WebPart"); //alert(sT.length); } while (sT.length<4 && p.parentNode.id!="MSO_ContentTable") if (p.getAttribute("contenteditable")=="true"){ return; } if (p.nodeName=="DIV"){ //alert("in if"); //alert(p.innerHTML); sep=document.createElement("div"); p.insertBefore(sep,p.firstChild); tabRow=document.createElement("div"); p.insertBefore(tabRow,p.firstChild); //alert(p.innerHTML); } else{ //alert("in else") sep=document.createElement("td"); var sepTR=document.createElement("tr"); sepTR.appendChild(sep); tabRow=document.createElement("td"); var tabTR=document.createElement("tr"); tabTR.appendChild(tabRow); if (p.nodeName=="TBODY"){ p.insertBefore(sepTR,p.firstChild); p.insertBefore(tabTR,p.firstChild); } else if (p.nodeName=="TR"){ p.parentNode.insertBefore(tabTR,p); p.parentNode.insertBefore(sepTR,p); } else { return; }

} sep.className="et-separator"; tabRow.className="et-tabrow"; var children=p.childNodes; p=p.parentNode; var etRoot=[],etHeader=[],etTab=[],tabsID=[]; for (var j=0; j<children.length; j++){ try{ var d=children[j].getElementsByTagName("span"); for (i=0; i<d.length; i++) { //alert (d.html); if(d[i].id.indexOf("WebPartTitle")==0){ var WPid=d[i].id.replace(/WebPartTitle/,""); if (d[i].innerHTML.indexOf("(Hidden)")==-1) { var up=d[i]; while (up!=children[j]){ if (up.parentNode.innerHTML.indexOf('id=WebPart'+WPid+' ')>=0||up.parentNode.innerHTML.indexOf('id="WebPart'+WPid+'" ')>=0){ WPid="et"+WPid; etHeader[WPid]=up; etRoot[WPid]=children[j]; etTab[WPid]=d[i].getElementsByTagName("span")[0].cloneNode(true); etTab[WPid].id=WPid; etTab[WPid].className="et-tab et-inactivetab"; etTab[WPid].onclick=function(){ activateTab(this); }; tabRow.appendChild(etTab[WPid]); tabsID.push(WPid); break; } up=up.parentNode; } } } } } catch(e){} } var Tabs=tabRow.getElementsByTagName("span"),TabCount=Tabs.length; if (Split=="Yes") { var sd=document.createElement("div"),index=Math.floor(TabCount*0.5); tabRow.insertBefore(sd,Tabs[index]); } if(AP.length && sec>0) { sec=sec*1000; interval=""; a=document.createElement("span"); a.innerHTML="|>"; a.className="et-tab et-inactivetab"; a.onclick=function(){ if(interval==""){ this.innerHTML="||"; interval=window.setInterval(function(){ Autoplay(); } ,sec) } else{ this.innerHTML="|>"; window.clearInterval(interval); interval="" } }; tabRow.appendChild(a); var Autoplay=function(){ for(i=0; i<TabCount; i++)if(Tabs[i].className=="et-tab et-activetab"){ var j=(i+1)%TabCount; activateTab(Tabs[j]); break } }; if (AP=="Play"){ a.innerHTML="||"; interval=window.setInterval(function(){ Autoplay(); } ,sec) }; } if (Expand.length) { a=document.createElement("span"); a.innerHTML=Expand; a.className="et-tab et-inactivetab"; a.onclick=function(){ for(i=0; i<tabsID.length; i++){ etTab[tabsID[i]].className="et-tab et-inactivetab"; etRoot[tabsID[i]].className=etRoot[tabsID[i]].className.replace(/et-offscreen/g,""); etRoot[tabsID[i]].style.pageBreakAfter="always"; etHeader[tabsID[i]].style.display=""; } }; tabRow.appendChild(a); } if (Print.length) { a=document.createElement("span"); a.innerHTML=Print; a.className="et-tab et-inactivetab"; a.onclick=function(){ this.style.display="none"; var f=document.getElementById("s4-workspace")||document.getElementsByTagName("body")[0],ed=p.parentNode.insertBefore(document.createElement(p.nodeName),p); f.appendChild(p); for (j=0; j<f.childNodes.length-1; j++) { try{ f.childNodes[j].className+=" et-offscreen"; } catch(e){} } a=document.createElement("span"); a.innerHTML="Back to Page"; a.className="et-tab et-inactivetab"; a.onclick=function(){ this.previousSibling.style.display="inline-block"; this.parentNode.removeChild(this); ed.parentNode.insertBefore(p,ed); ed.parentNode.removeChild(ed); for (j=0; j<f.childNodes.length; j++) { try{ f.childNodes[j].className=f.childNodes[j].className.replace(/\s*et-offscreen/g,""); } catch(e){} } }; tabRow.appendChild(a); }; tabRow.appendChild(a); } function activateTab(t){ document.cookie=tabsID.join("_")+"="+t.id+";path=/"; for(i=0; i<tabsID.length; i++){ etHeader[tabsID[i]].style.display=Header; if(t.id==tabsID[i]){ etTab[tabsID[i]].className="et-tab et-activetab"; etRoot[tabsID[i]].className=etRoot[tabsID[i]].className.replace(/\s*et-offscreen/g,""); } else{ etTab[tabsID[i]].className="et-tab et-inactivetab"; etRoot[tabsID[i]].className+=" et-offscreen"; } } } var m=GetCookie(tabsID.join("_"))?GetCookie(tabsID.join("_")):tabsID[0]; activateTab(etTab[m]);

})();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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