我有一个要求,当用户打开网站时打开弹出消息框,但它应该只在第一次打开。假设用户关闭窗口并再次打开网站,那么它应该再次显示。这怎么可能?有脚本吗?
最佳答案
您可以使用setcookie存储一个非持久 cookie,以记住您之前是否显示过弹出消息。
要设置非持久性 Cookie,只需将过期时间留空或设置为 0。
If set to 0, or omitted, the cookie will expire at the end of the session (when the browser closes).
您可以这样添加:
setcookie('seen_popup', true);
然后检查用户之前是否看过它:
if(!isset($_COOKIE['seen_popup'])):
// print your popup..
<div id="popup">
My message
</div>
endif;
在 jQuery 中,在显示弹出窗口之前检查它是否存在:
if($('#popup').length){
// execute code
}
关于javascript - PHP在网站打开时打开弹出窗口但只是第一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39218542/