Reputation: 329
I need to go from home.html to services.html, the class .services_profile is a sub-menu that needs to go to services.html and make the .services_profile_tab active
$(".services_profile").click(function(e){
$('.nav-tabs li a.tab-profile').attr("aria-expanded","true").parent().siblings().removeClass('active');
$('.nav-tabs li a.tab-profile').parent().addClass('active');
$('.tab-content').children().removeClass('in active');
$('.tab-content .profile').addClass('in active');
setTimeout(function() {
window.location.href = 'services.html';
},1000);
// This does not work
if (window.location.pathName.indexOf('services') >= 0) {
$('services_profile_tab').addclass('active');
}
});
Upvotes: 0
Views: 210
Reputation: 67525
The pathname should be in lowercase in :
if (window.location.pathName.indexOf('services') >= 0) {
And also you've missing a dot .
of class before services_profile_tab
in :
$('services_profile_tab').addclass('active');
Hope this helps.
Upvotes: 1
Reputation: 74748
you need to pass the tab reference to the services page Either within the url
or you can make use of window.localStorage
to set the specific tab to get active on navigating to the specific page like this with passing a ref in the url with hash:
$(".services_profile").click(function(e){
$('.nav-tabs li a.tab-profile').attr("aria-expanded","true")
.parent().siblings().removeClass('active');
$('.nav-tabs li a.tab-profile').parent().addClass('active');
$('.tab-content').children().removeClass('in active');
$('.tab-content .profile').addClass('in active');
setTimeout(function() {
window.location.href = 'services.html#services_profile_tab';// pass the tab reference
},1000);
});
now on the services page in the doc ready block:
$(function(){
if (window.location.indexOf('services') >= 0) {
var tab = window.location.hash.substr(1);
$('.'+tab).addclass('active');
}
});
Something you can do to pass the tab reference dynamically like:
window.location.href = this.className.split('_')[0]'.html#'+this.className+'_tab';
// so it results in
// services.html#services_profile_tab => when "services_profile" clicked
here this.className
is the clicked element to navigate.
Upvotes: 0