Solved

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

Posted on 2010-09-15
3
431 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

867 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

21 Experts available now in Live!

Get 1:1 Help Now