Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
jQuery Multiple Tab with Cookie?
Old 01-06-2010, 01:14 PM jQuery Multiple Tab with Cookie?
Junior Talker

Posts: 3
Trades: 0
A jQuery noob here.

I've found a jQuery tab script that can set up multiple tab sets however I need the ability to remember which last tab I clicked so that when I refresh the page, it will still be active. I read about the jQuery cookie plugin but I don't understand how to implement it.

I badly need this functionality (jQuery cookie plugin) to be added in the existing code below. It will be use for my personal site. I only know HTML and a little in CSS.

Below is the code:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Tabs</title>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$.fn.myTabs = function() {
		$(this).find('.tab_content').hide();
		$(this).find('.tab li:first').addClass('active').show();
		$(this).find('.tab_content:first').show();
		
		$('.tab li').click(function() {
			$(this).parent().parent().parent().find('.tab li').removeClass('active');
			$(this).addClass('active');			
			$(this).parent().parent().parent().find('.tab_content').hide();
			var activeTab = $(this).find('a').attr('href');
			$(activeTab).show();
			return false;
		});
	};
	$("div[class^='my_tabs']").myTabs();
});
</script>
</head>
<body>
<div class="my_tabs">
	<div class="tab">
		<ul class="clearfix">
			<li><a href="#comments"><span>Latest Comments</span></a></li>
			<li><a href="#popular"><span>Recently Popular</span></a></li>
			<li><a href="#tags"><span>Tag Cloud</span></a></li>
		</ul>
	</div>
	<div class="box">
		<div class="tab_content" id="comments">
			Latest Comments Content
		</div>		
		<div class="tab_content" id="popular">
			Popular Content
		</div>
		<div class="tab_content" id="tags">
			Tag Cloud Content
		</div>
	</div>
</div>
<br />
<div class="my_tabs">
	<div class="tab">
		<ul class="clearfix">
			<li><a href="#tab1"><span>Tab 1</span></a></li>
			<li><a href="#tab2"><span>Tab 2</span></a></li>
			<li><a href="#tab3"><span>Tab 3</span></a></li>
		</ul>
	</div>
	<div class="box">
		<div class="tab_content" id="tab1">
			Tab One Content
		</div>		
		<div class="tab_content" id="tab2">
			Tab Two Content
		</div>
		<div class="tab_content" id="tab3">
			Tab Three Content
		</div>
	</div>
</div>
</body>
</html>
I appreciate any kind of help.
bloggerious is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-10-2010, 11:23 AM Re: jQuery Multiple Tab with Cookie?
Junior Talker

Posts: 3
Trades: 0
Anyone willing to help?
bloggerious is offline
Reply With Quote
View Public Profile
 
Old 01-10-2010, 01:32 PM Re: jQuery Multiple Tab with Cookie?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Do you have a specific question? It is difficult to explain jQuery if you don't understand CSS well and have never programmed.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 01-10-2010, 07:16 PM Re: jQuery Multiple Tab with Cookie?
Junior Talker

Posts: 3
Trades: 0
My question is how to modify the code I posted so that it will remember the last Tab I clicked.

For example, if I have Tab1, Tab 2, Tab 3. When I click Tab 3 and refresh the page, it will go back to the default Tab 1 which is not what I want. I want that it will still be the Tab 3 that should be active even if I refresh the page.
bloggerious is offline
Reply With Quote
View Public Profile
 
Old 01-10-2010, 11:04 PM Re: jQuery Multiple Tab with Cookie?
Banned

Posts: 421
Location: Boston, MA
Trades: 1
Quote:
Originally Posted by bloggerious View Post
My question is how to modify the code I posted so that it will remember the last Tab I clicked.

For example, if I have Tab1, Tab 2, Tab 3. When I click Tab 3 and refresh the page, it will go back to the default Tab 1 which is not what I want. I want that it will still be the Tab 3 that should be active even if I refresh the page.
on that case you may use a session or you can redirect to the url with a different querystring for each tab.
webcosmo is offline
Reply With Quote
View Public Profile Visit webcosmo's homepage!
 
Old 01-11-2010, 08:33 AM Re: jQuery Multiple Tab with Cookie?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
There's no URL from what I can tell that will open the tab, it is an event based, from a click event. If this is the case, you could place the number of the tab into the cookie, then use jQuery's click() function to create a click instead of setting an event with it.

This assumes that there is a variable called cookie that you've populated with this data:
Code:
if(typeof cookie != "undefined") {
    $(".tab li").eq(cookie).click();//
}
This would have to be the last thing on the page, and you will have to find a way to put a number into a cookie (starting with zero for the first tab, not one), every time a tab is clicked on. It shouldn't be hard.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to jQuery Multiple Tab with Cookie?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23198 seconds with 12 queries