[英]how to make a pop up appear only once in html using javascript
i have my age verification pop up i want to appear only once when the site is visited and the pop up keeps appearing each item i refresh my browser, how do i go about it?我有我的年龄验证弹出我只想在访问该网站时出现一次,并且弹出窗口不断出现我刷新浏览器的每个项目,我该怎么做? answer will be much appreciated.答案将不胜感激。
if (document.getElementById("newsletter-popup-form")) {
setTimeout(function () {
var mpInstance = $.magnificPopup.instance;
if (mpInstance.isOpen) {
mpInstance.close();
}
setTimeout(function () {
$.magnificPopup.open({
items: {
src: "#newsletter-popup-form",
},
type: "inline",
removalDelay: 350,
callbacks: {
open: function () {
$("body").css("overflow-x", "visible");
$(".sticky-header.fixed").css("padding-right", "1.7rem");
},
close: function () {
$("body").css("overflow-x", "hidden");
$(".sticky-header.fixed").css("padding-right", "0");
},
},
});
}, 500);
}, 100);
}
HTML HTML
<!--(place this inside the popup)-->
<input id="age-input" />
JS JS
const popup = document.getElementById("newsletter-popup-form")
const ageInput = document.getElementById("age-input")
ageInput.addEventListener(change, (e) => {
localStorage['userAge'] = ageInput.value;
}
if if (localStorage.getItem("userAge") === null) { {
// shows the popup on refresh so long as variable is not found
popup.style.display="block";
//insert any additional code here...
} else {
// hides the popup
popup.style.display="none";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.