I have one requirement to open popup message box when user open website but it should be open first time only. Suppose user close window and open website again then it should be display again.How it is possible? any script ?
Asked
Active
Viewed 1,365 times
1
-
See http://stackoverflow.com/questions/29986657/global-variable-usage-on-page-reload/ – guest271314 Aug 30 '16 at 04:39
1 Answers
0
You can use setcookie to store a non-persistent cookie to remember if you've shown the popup message previously.
To set a non-persistent cookie, you simply leave the expiration time empty or set it to 0.
If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).
You can add it like this:
setcookie('seen_popup', true);
Then check if the user has seen it previously:
if(!isset($_COOKIE['seen_popup'])):
// print your popup..
<div id="popup">
My message
</div>
endif;
And in jQuery, check if the popup exists before showing it:
if($('#popup').length){
// execute code
}

Chin Leung
- 14,621
- 3
- 34
- 58