Solved

Hide a Div As a Session State - after Div is hidden it remains hidden on subsequent pages

Posted on 2010-09-15
3
429 Views
Last Modified: 2012-05-10
I'm new to JS and jQuery.. I have "all" the books and am doing my home work.  But some things are still opaque. I will be putting a banner across the tops of all pages on a site for 3 months, I'll bring in this one code chunk using SSI and banners will change, but we want to put a "Hide" button on it so if some user wants to turn it off for the current session, he can. I don't want to store that as a preference in a cookie, but only for the current session.  

OK, now, the animate tool in jQuery is quite transparent and the documentation in the jQuery Cookbook, which I have is also very simple. BUT:  if I implement this on one page, when the user goes to the next page, the div will appear again. How do I trap the banner state? In effect, make "display:none"  "sticky", as the user traverses many pages.  I will go and see if I can study up on sessions, but I have a short time frame to get this done and I'm not sure I'll grok everything on time.  Any help will be appreciated.
0
Comment
Question by:Sivakatirswami
  • 2
3 Comments
 
LVL 9

Expert Comment

by:wellhole
ID: 33684746
One easy way is to use a session only cookie.
0
 
LVL 2

Accepted Solution

by:
WilliamStam earned 500 total points
ID: 33711105
checkout the jQuery cookie plugin.. theres a session only cookie option (when you dont set an expiry date thing)

on click set the session cookie.. then just have a if session cookie == "thisNthat" then hide banner

session state cookies are the same as a server side session..

http://plugins.jquery.com/files/jquery.cookie.js.txt

$("#hidebtn").click(function(){
$.cookie('the_cookie', 'hideme');
});

if ( $.cookie('the_cookie') == "hideme" ){
$("#banner").addClass("showthebannerclass");
};

since the cookie is set... maybe use a server side cookie check.. otherwise the page will load normaly then when it gets to running the js it will suddenly hide it..
0
 
LVL 2

Expert Comment

by:WilliamStam
ID: 33711107
other options is to maybe use a query string... but you better off with the session route
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now