Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

840 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