Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-19-2011, 07:58 PM   PM User | #1
defencedog
New Coder

 
Join Date: Mar 2011
Location: Pakistan
Posts: 85
Thanks: 20
Thanked 0 Times in 0 Posts
defencedog has a little shameless behaviour in the past
Jquery Cookie Problem

I hav done quite a homework in determining the code to be precise the 'cookie code' such that the browser remember my choice!
Vistt this : https://defencedog.googlecode.com/sv...lcome_box.html

by viewing the source you will determine the two jquery (essential files) that are needed & I ain't tempering with them.
However I had tried to customise this passage:

Code:
<script type="text/javascript" language="javascript"> 

$(document).ready(function() {
	$('#sliderBox').slideTo({
		transition:300,
		top:'center',
		left:'center',
		inside:window
	});
	$('#mask').height($(document).height());

	jQuery(window).resize(function() {
		$('#sliderBox').stop().slideTo({
			transition:300,
			top:'center',
			left:'center',
			inside:window
		});
	});

	var closeWelcomeBox;

	$(window).scroll(function(){ 
		if(!closeWelcomeBox){
			$('#sliderBox').stop().slideTo({
				transition:300,
				top:'center',
				left:'center',
				inside:window
			});
		}
	});

	
	$("#closeWelcomeBox").click(function(){
		$('#sliderBox').stop().slideTo({ 
			transition:500,
			top:-400
	    	});
	    	$('#mask').fadeOut(500);
		closeWelcomeBox = true;
		$.cookie('hidewelcome', 'collapsed');
	});
	
	// COOKIES
    var hidewelcome = $.cookie('hidewelcome');
    if (hidewelcome == 'collapsed') {
        $('#sliderBox').css("display","none");
        $('#mask').css("display","none");
        closeWelcomeBox = true;
    };
});

</script>
First I created a cookie when the button is clicked & giv it its respective property namely 'collapse':
Code:
$.cookie('hidewelcome', 'collapsed');
then I simply wrote this to make browser remember users click event choice (via cookie):
Code:
	// COOKIES
    var hidewelcome = $.cookie('hidewelcome');
    if (hidewelcome == 'collapsed') {
        $('#sliderBox').css("display","none");
        $('#mask').css("display","none");
        closeWelcomeBox = true;
    };
This isn't working or am I missing something
defencedog is offline   Reply With Quote
Old 09-19-2011, 09:59 PM   PM User | #2
harbingerOTV
Senior Coder

 
Join Date: Jan 2005
Location: Memphis, TN
Posts: 1,765
Thanks: 8
Thanked 123 Times in 121 Posts
harbingerOTV will become famous soon enough
error: $.cookie is not a function

you need to include the scrip that actually sets the cookie: https://github.com/carhartl/jquery-cookie
__________________
Stop making things so hard on yourself.
i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis
harbingerOTV is offline   Reply With Quote
Users who have thanked harbingerOTV for this post:
defencedog (09-19-2011)
Old 09-19-2011, 10:35 PM   PM User | #3
defencedog
New Coder

 
Join Date: Mar 2011
Location: Pakistan
Posts: 85
Thanks: 20
Thanked 0 Times in 0 Posts
defencedog has a little shameless behaviour in the past
Quote:
Originally Posted by harbingerOTV View Post
error: $.cookie is not a function

you need to include the scrip that actually sets the cookie: https://github.com/carhartl/jquery-cookie
you made chemical engineer a day!!

however may I ask is this can be done without adding external javascript & is there way to clear a cookie automatically lets say after 24hr period. (so the welcome popup appears to a user after 24hr)

I will use this script on blogger: http://defencedog.blogspot.com/
defencedog is offline   Reply With Quote
Old 09-19-2011, 10:56 PM   PM User | #4
harbingerOTV
Senior Coder

 
Join Date: Jan 2005
Location: Memphis, TN
Posts: 1,765
Thanks: 8
Thanked 123 Times in 121 Posts
harbingerOTV will become famous soon enough
You can embed the script in your page as opposed to it being external.

http://plugins.jquery.com/files/issu...dified.js_.txt

and here are options:
https://github.com/carhartl/jquery-c...er/README.rdoc

Using that documentation and making it expire after 24 hours eg:

$.cookie('the_cookie', 'the_value', { expires: 1 }); /*1 is in days */
__________________
Stop making things so hard on yourself.
i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis
harbingerOTV is offline   Reply With Quote
Users who have thanked harbingerOTV for this post:
defencedog (09-20-2011)
Old 09-20-2011, 01:48 AM   PM User | #5
defencedog
New Coder

 
Join Date: Mar 2011
Location: Pakistan
Posts: 85
Thanks: 20
Thanked 0 Times in 0 Posts
defencedog has a little shameless behaviour in the past
Problem Solved
defencedog is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 10:48 PM.


Advertisement
Log in to turn off these ads.