I have a function that is launched by the button "Calculate"
I need this line to be executed only once per session (the session can be 1 day or until the browser restarts).
$('.popup-with-form').magnificPopup('open');
A popup will open. When this function is executed (the pop-up window opens), if the "calculate" button is pressed again, I do not want the pop-up window to open again.
JS / JQuery Code:
function StateChanged() { if (XmlHttp.readyState == 4 || XmlHttp.readyState == "complete") { $('.popup-with-form').magnificPopup('open'); document.getElementById("CalcSum").innerHTML = XmlHttp.responseText; document.getElementById("CalcSumPopup").innerHTML = XmlHttp.responseText; } }
PS I know that many of these questions come up, and I tried different ways of doing something, but since I am “code-sensitive” and don’t know JQuery or JS, I can’t figure it out. I know that in jQuery there is a .one "thing, but I don’t understand how to make it work.
I really welcome any help. Thanks!
UPDATE Question answered by @MarcoBonelli - Thank you!
Working solution:
if (!sessionStorage.alreadyClicked) { $('.popup-with-form').magnificPopup('open'); sessionStorage.alreadyClicked = "true"; }
source share