A
A
Alpha122019-09-09 13:41:18
JavaScript
Alpha12, 2019-09-09 13:41:18

How to show a window to a person only once?

Good afternoon!
There is a popup window, I need it to be displayed only in the mobile version and only once.

How can I make it so that if the person closes the window, it won't show again until they close the browser?

Tell me, do you need cookies?

$(document).ready(function() {    
          if ($(window).width() < 768 ) {    
    		$('#mobile').show();   
    	$('#mobile span').click(function() {
    		$('#mobile').hide();
    	});
    }        
    	});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene Chefranov, 2019-09-09
@Alpha12

$(document).ready(function() {
  if ($(window).width() < 768) {
    if (localStorage.getItem("modal") != "off") {
      $("#mobile").show();
    }
    $("#mobile span").click(function() {
      $("#mobile").hide();
      localStorage.setItem("modal", "off");
    });
  }
});

If it will be necessary not forever, but before closing the browser tab, then replace localStorage with sessionStorage

A
Anton, 2019-09-09
@Eridani

If it does not close the browser yet, then Session Storage

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question