Div with “close” functions on more than one page











up vote
0
down vote

favorite












I have a div called "alert-box-close" that will appear on the page and be closed on X and reappear after 1 minut (just for testing purposes, after that the expiring time will be 30 days).



The problem is that I have three pages that need the same div, but if it's closed on one of the pages, it should appear if another page is opened. With this code in each of pages will reappear only when the indicated time is expired.
How to correct this?
Thank you in advance.






$(document).ready(function() {
// Add hours function
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + 60000); // 60 seconds for testing
return this;
}
//Hide div click
$('.alert-box-close').click(function() {
//Get time after 24 hours
var after24 = new Date().addHours(10).getTime();
//Hide div
$('#alert-box-news').hide(300);
//Set desired time till you want to hide that div
localStorage.setItem('desiredTime', after24);
});
//If desired time >= currentTime, based on that HIDE / SHOW
function checkStorage() {
var currentTime = new Date().getTime();
if (localStorage.getItem('desiredTime') >= currentTime) {
$('#alert-box-news').hide();
} else {
$('#alert-box-news').show();
}
}
//Check logic on load
checkStorage();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="alert-box-news" class="alert-box alertboxone alerthidden">
<img src="https://no-cache.hubspot.com/cta/default/4409803/2e194850-79d4-4b68-bd48-dc8e559edd96.png"/>
<img class="alert-box-close closeone" id="close-alert-box-news" src="https://www.atakinteractive.com/wp-content/uploads/2018/11/closeiframe.png">
</div>












share|improve this question
























  • Include your HTML too
    – Just code
    Nov 20 at 11:23










  • Html added above
    – Mara Barn
    Nov 20 at 11:28















up vote
0
down vote

favorite












I have a div called "alert-box-close" that will appear on the page and be closed on X and reappear after 1 minut (just for testing purposes, after that the expiring time will be 30 days).



The problem is that I have three pages that need the same div, but if it's closed on one of the pages, it should appear if another page is opened. With this code in each of pages will reappear only when the indicated time is expired.
How to correct this?
Thank you in advance.






$(document).ready(function() {
// Add hours function
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + 60000); // 60 seconds for testing
return this;
}
//Hide div click
$('.alert-box-close').click(function() {
//Get time after 24 hours
var after24 = new Date().addHours(10).getTime();
//Hide div
$('#alert-box-news').hide(300);
//Set desired time till you want to hide that div
localStorage.setItem('desiredTime', after24);
});
//If desired time >= currentTime, based on that HIDE / SHOW
function checkStorage() {
var currentTime = new Date().getTime();
if (localStorage.getItem('desiredTime') >= currentTime) {
$('#alert-box-news').hide();
} else {
$('#alert-box-news').show();
}
}
//Check logic on load
checkStorage();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="alert-box-news" class="alert-box alertboxone alerthidden">
<img src="https://no-cache.hubspot.com/cta/default/4409803/2e194850-79d4-4b68-bd48-dc8e559edd96.png"/>
<img class="alert-box-close closeone" id="close-alert-box-news" src="https://www.atakinteractive.com/wp-content/uploads/2018/11/closeiframe.png">
</div>












share|improve this question
























  • Include your HTML too
    – Just code
    Nov 20 at 11:23










  • Html added above
    – Mara Barn
    Nov 20 at 11:28













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a div called "alert-box-close" that will appear on the page and be closed on X and reappear after 1 minut (just for testing purposes, after that the expiring time will be 30 days).



The problem is that I have three pages that need the same div, but if it's closed on one of the pages, it should appear if another page is opened. With this code in each of pages will reappear only when the indicated time is expired.
How to correct this?
Thank you in advance.






$(document).ready(function() {
// Add hours function
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + 60000); // 60 seconds for testing
return this;
}
//Hide div click
$('.alert-box-close').click(function() {
//Get time after 24 hours
var after24 = new Date().addHours(10).getTime();
//Hide div
$('#alert-box-news').hide(300);
//Set desired time till you want to hide that div
localStorage.setItem('desiredTime', after24);
});
//If desired time >= currentTime, based on that HIDE / SHOW
function checkStorage() {
var currentTime = new Date().getTime();
if (localStorage.getItem('desiredTime') >= currentTime) {
$('#alert-box-news').hide();
} else {
$('#alert-box-news').show();
}
}
//Check logic on load
checkStorage();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="alert-box-news" class="alert-box alertboxone alerthidden">
<img src="https://no-cache.hubspot.com/cta/default/4409803/2e194850-79d4-4b68-bd48-dc8e559edd96.png"/>
<img class="alert-box-close closeone" id="close-alert-box-news" src="https://www.atakinteractive.com/wp-content/uploads/2018/11/closeiframe.png">
</div>












share|improve this question















I have a div called "alert-box-close" that will appear on the page and be closed on X and reappear after 1 minut (just for testing purposes, after that the expiring time will be 30 days).



The problem is that I have three pages that need the same div, but if it's closed on one of the pages, it should appear if another page is opened. With this code in each of pages will reappear only when the indicated time is expired.
How to correct this?
Thank you in advance.






$(document).ready(function() {
// Add hours function
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + 60000); // 60 seconds for testing
return this;
}
//Hide div click
$('.alert-box-close').click(function() {
//Get time after 24 hours
var after24 = new Date().addHours(10).getTime();
//Hide div
$('#alert-box-news').hide(300);
//Set desired time till you want to hide that div
localStorage.setItem('desiredTime', after24);
});
//If desired time >= currentTime, based on that HIDE / SHOW
function checkStorage() {
var currentTime = new Date().getTime();
if (localStorage.getItem('desiredTime') >= currentTime) {
$('#alert-box-news').hide();
} else {
$('#alert-box-news').show();
}
}
//Check logic on load
checkStorage();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="alert-box-news" class="alert-box alertboxone alerthidden">
<img src="https://no-cache.hubspot.com/cta/default/4409803/2e194850-79d4-4b68-bd48-dc8e559edd96.png"/>
<img class="alert-box-close closeone" id="close-alert-box-news" src="https://www.atakinteractive.com/wp-content/uploads/2018/11/closeiframe.png">
</div>








$(document).ready(function() {
// Add hours function
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + 60000); // 60 seconds for testing
return this;
}
//Hide div click
$('.alert-box-close').click(function() {
//Get time after 24 hours
var after24 = new Date().addHours(10).getTime();
//Hide div
$('#alert-box-news').hide(300);
//Set desired time till you want to hide that div
localStorage.setItem('desiredTime', after24);
});
//If desired time >= currentTime, based on that HIDE / SHOW
function checkStorage() {
var currentTime = new Date().getTime();
if (localStorage.getItem('desiredTime') >= currentTime) {
$('#alert-box-news').hide();
} else {
$('#alert-box-news').show();
}
}
//Check logic on load
checkStorage();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="alert-box-news" class="alert-box alertboxone alerthidden">
<img src="https://no-cache.hubspot.com/cta/default/4409803/2e194850-79d4-4b68-bd48-dc8e559edd96.png"/>
<img class="alert-box-close closeone" id="close-alert-box-news" src="https://www.atakinteractive.com/wp-content/uploads/2018/11/closeiframe.png">
</div>





$(document).ready(function() {
// Add hours function
Date.prototype.addHours = function(h) {
this.setTime(this.getTime() + 60000); // 60 seconds for testing
return this;
}
//Hide div click
$('.alert-box-close').click(function() {
//Get time after 24 hours
var after24 = new Date().addHours(10).getTime();
//Hide div
$('#alert-box-news').hide(300);
//Set desired time till you want to hide that div
localStorage.setItem('desiredTime', after24);
});
//If desired time >= currentTime, based on that HIDE / SHOW
function checkStorage() {
var currentTime = new Date().getTime();
if (localStorage.getItem('desiredTime') >= currentTime) {
$('#alert-box-news').hide();
} else {
$('#alert-box-news').show();
}
}
//Check logic on load
checkStorage();
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="alert-box-news" class="alert-box alertboxone alerthidden">
<img src="https://no-cache.hubspot.com/cta/default/4409803/2e194850-79d4-4b68-bd48-dc8e559edd96.png"/>
<img class="alert-box-close closeone" id="close-alert-box-news" src="https://www.atakinteractive.com/wp-content/uploads/2018/11/closeiframe.png">
</div>






jquery function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 12:38









Calvin Nunes

3,6232933




3,6232933










asked Nov 20 at 11:20









Mara Barn

458




458












  • Include your HTML too
    – Just code
    Nov 20 at 11:23










  • Html added above
    – Mara Barn
    Nov 20 at 11:28


















  • Include your HTML too
    – Just code
    Nov 20 at 11:23










  • Html added above
    – Mara Barn
    Nov 20 at 11:28
















Include your HTML too
– Just code
Nov 20 at 11:23




Include your HTML too
– Just code
Nov 20 at 11:23












Html added above
– Mara Barn
Nov 20 at 11:28




Html added above
– Mara Barn
Nov 20 at 11:28

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391890%2fdiv-with-close-functions-on-more-than-one-page%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391890%2fdiv-with-close-functions-on-more-than-one-page%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'