-1

i have script in my popup

$(function() {
$('.window_content a.window_close').on('click', function(e) {
    e.preventDefault();

    $(this).parent().removeClass('opened');
    $('#window_overlay').removeClass('opened');
});

$('.window_content').addClass('opened');
$('#window_overlay').addClass('opened');

I need to add a cookie support so that this popup is displayed at the specified time and it was not displayed every time the page was refreshed

Any help really appreciated, thank you!

Now i Try Use LocalStorage but popup does not disappear from the page when i refresh ;/

<script>
    $(function() {
    $('.window_content a.window_close').on('click', function(e) {
        e.preventDefault();
 
        $(this).parent().removeClass('opened');
        $('#window_overlay').removeClass('opened');
    });
    
    if(localStorage.getItem('window_overlay') != 'shown') {
     $(this).delay(2000).fadeIn();
     localStorage.setItem('window_overlay','shown')
    }
    
    $('.window_content').addClass('opened');
    $('#window_overlay').addClass('opened');
});
</script>
m.stasica
  • 1
  • 2
  • 1
    Please go read [ask]. This is not a code-writing service, we expect you to make an initial attempt. – CBroe Dec 01 '20 at 09:31
  • I made my first attempt to write this PopUp but I don't know how to connect Jquerry Cookies to it – m.stasica Dec 01 '20 at 09:39
  • @m.stasica, what do you mean by specified time? can you elaborate please – the.marolie Dec 01 '20 at 09:42
  • @m.stasica, If you want to display the popup only on a first visit, then you can either store a flag in local storage/cookies and then display the popup based on the flag value every time a user visits. you can refer this to set/unset cookies - [link](https://stackoverflow.com/questions/1458724/how-do-i-set-unset-a-cookie-with-jquery) – the.marolie Dec 01 '20 at 09:46
  • @akshithDayanand, For this Popup to be displayed, for example, Every Hour or Day I also read that can use "localStorage" to be displayed only on the home page Can you help with this? – m.stasica Dec 01 '20 at 09:48
  • I use this example but this is not work ;c – m.stasica Dec 01 '20 at 09:51
  • I can't understand the question. Your sentences are not written properlyly. Please try and correct them and clarify. – Yosef Bernal Dec 01 '20 at 10:15
  • @Yosef Bernal i correct my question about localstorage – m.stasica Dec 01 '20 at 10:58
  • @m.stasica, could you please the html code for popup as well? – the.marolie Dec 02 '20 at 10:46

1 Answers1

0
$(function() {
$('.window_content a.window_close').on('click', function(e) {
    e.preventDefault();

    $(this).parent().addclass('opened');
    $('#window_overlay').addclass('opened');
    });

    if(localStorage.getItem('window_overlay') != 'shown') {
     $(this).delay(2000).fadeIn();
     localStorage.setItem('window_overlay','shown')
  }
   });