Open page on tab # 2 using bootstrap

I am linking to a page that uses tabs (Bootstrap). By default it always opens on tab # 1, for the most part this is ok, but for this particular link I want for it to open on tab# 2

This is my link:

links_index.asp?caseid=<%=(rs_case.Fields.Item("Id").Value)%>

This is the code for the tabs:

    <ul class="nav nav-tabs">
      <li class="active"><a data-toggle="tab" href="#tab-1">Users</a></li>
      <li class=""><a data-toggle="tab" href="#tab-2">Sponsoring Employer</a></li>
    </ul>
LVL 1
AleksAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
Can you put a hash at the end?

links_index.asp?caseid=<%=(rs_case.Fields.Item("Id").Value)%>#tab-2

Then add some jQuery to switch the tabs on document ready.
$(function(){
	var url = document.location.toString();
	if (url.match('#')) {
		$('.nav-tabs a[href=#'+url.split('#')[1]+']').tab('show') ;
	} 
});

Open in new window

AleksAuthor Commented:
It works, moves the page to tab# 2 ... the only problem I find is that it also scrolls the page all the way down, can this be avoided ?
Tom BeckCommented:
Sure. Rather than add a hash to the url, add another parameter to indicate what tab you want to open with. Call it "tab".

links_index.asp?caseid=<%=(rs_case.Fields.Item("Id").Value)%>&tab=tab-2

Then use this script:
$(function(){
	$('.nav-tabs a[href=#'+ getParameterByName('tab') +']').tab('show');
});
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

AleksAuthor Commented:
Perfect ! You da man  :)
AleksAuthor Commented:
Perfect !
Tom BeckCommented:
Glad it worked for you. Thanks for the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTML

From novice to tech pro — start learning today.