Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
61
rated 0 times [  64] [ 3]  / answers: 1 / hits: 143180  / 10 Years ago, thu, june 12, 2014, 12:00:00

There have already been answers to this question but I am still unsure exactly how it works.



I am using the following HTML in my footer.php:



<div id=popup>
<div>
<div id=popup-close>X</div>
<h2>Content Goes Here</h2>
</div>
</div>


and the following Javascript:



$j(document).ready(function() {
$j(#popup).delay(2000).fadeIn();
$j('#popup-close').click(function(e) // You are clicking the close button
{
$j('#popup').fadeOut(); // Now the pop up is hiden.
});
$j('#popup').click(function(e)
{
$j('#popup').fadeOut();
});
});


Everything works great, but I want to only show the pop up once per user (maybe using the cookie thing all the forum posts go on about) but I do not know exactly how to incorporate it into the JS above.



I know that I will have to load the cookie JS in my footer with this:



<script type=text/javascript src=scripts/jquery.cookies.2.2.0.min.js></script> 


But that is all I understand, can anyone tell me exactly how the JS/jQuery should look with the cookie stuff added?



Thanks



James


More From » jquery

 Answers
22

*Note : This will show popup once per browser as the data is stored in browser memory.


Try HTML localStorage.


Methods :



  • localStorage.getItem('key');

  • localStorage.setItem('key','value');




$j(document).ready(function() {
if(localStorage.getItem('popState') != 'shown'){
$j('#popup').delay(2000).fadeIn();
localStorage.setItem('popState','shown')
}

$j('#popup-close, #popup').click(function() // You are clicking the close button
{
$j('#popup').fadeOut(); // Now the pop up is hidden.
});
});

Working Demo


[#70601] Tuesday, June 10, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emmaleet

Total Points: 203
Total Questions: 107
Total Answers: 98

Location: Cook Islands
Member since Thu, May 21, 2020
4 Years ago
emmaleet questions
Wed, Apr 28, 21, 00:00, 3 Years ago
Thu, Jan 7, 21, 00:00, 3 Years ago
Sat, Nov 28, 20, 00:00, 4 Years ago
Sat, Apr 18, 20, 00:00, 4 Years ago
;