Reputation: 158
I have to load pop up only one time when index page loads. I have used same body tag in every pages.
Here is my code,
Html File
<body>
---------
------------
<a id="ac" href="about.php">About</a>
</body>
Js File
$(document).ready(function(){
$("#ac").on("click", function(){
$('body').off(load);
});
loadPopUp();
});
function loadPopUp()
{
alert('xyz');
}
When my page went to "about.php" page, onload pop up should be disable.
Please give some suggestion or instruction regarding this.
Thanks.
Upvotes: 1
Views: 203
Reputation: 9782
Use the one method
$("#ac").one("click",function(){ });
The one method will fire once, then unbind.
If you would like to ensure the function only fires once ever, per browser, you can use localStorage.
if (localStorage.getItem("SomeSiteVisitFlag") === null) {
// Set the flag here (using the code in the event handler below)
// To indicate the user has visited any page of your site
$("#ac").one("click",function(){
// Set the flag here to indicate that the person clicked on #ac
localStorage.setItem("SomeSiteVisitFlag",true);
});
}
Upvotes: 0
Reputation: 821
You need to set a flag on your session storage, the flag will reset when you close browser,
$(document).ready(function(){
if(sessionStorage.getItem("popupflag")===null){
loadPopUp();
//sessionStorage.setItem("popupflag","true");
}
});
if you want to disable on anchor click use this code on click event
$("#ac").on("click", function(){
sessionStorage.setItem("popupflag","true");
});
Upvotes: 2