Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    85
    Thanks
    20
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    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

  • Users who have thanked harbingerOTV for this post:

    defencedog (09-19-2011)

  • #3
    New Coder
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    85
    Thanks
    20
    Thanked 0 Times in 0 Posts
    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/

  • #4
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    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

  • Users who have thanked harbingerOTV for this post:

    defencedog (09-20-2011)

  • #5
    New Coder
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    85
    Thanks
    20
    Thanked 0 Times in 0 Posts
    Problem Solved


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •