A javascript engine for scheduling alerts and content with built in auto-display/removal logic.
A javascript engine for scheduling alerts and content with built in auto-display/removal logic.
Add the latest Scheduling Engine files to the header of your site.
<script src="scheduling_engine.js"></script>
<script type="text/javascript">
window.onload = function(){
// Set the start and end dates/times (MM/DD/YY & HH/MM/SS)
dateCheck = scheduleEngine("January 1, 2019 11:59:00", "January 1, 2019 12:00:00");
// Identifies the target DOM element where the message should be appended
var id = 'alert';
// Message to be displayed
var message = document.createTextNode("This is a test message.");
// Expiration message to be displayed
var expirationMessage = document.createTextNode("This message has expired.");
// Checks for condition to be true
if (dateCheck == 1) {
document.getElementById(id).appendChild(message); // Set ID to the targeted element
} else {
document.getElementById(id).appendChild(expirationMessage); // Set ID to the targeted element
}
};
</script>
<div id="alert"></div>
For deployment use the minified version instead:
<script src="scheduling_engine.min.js"></script>
Add an HTML element in the <body>
of your site. This will be used later to connect the schedule engine logic to the DOM.
<div id="alert"></div>
Start and end dates are set in the MM/DD/YY and HH/MM/SS formats. Search for the scheduleEngine
function and set the sDate
and eDate
.
dateCheck = scheduleEngine("January 1, 2018 11:59:00", "January 1, 2018 12:00:00");
In the dateCheck
conditional statement change #alert
to the ID you assigned to your DOM element.
document.getElementById(id).appendChild(message); // Set ID to the targeted element
Once done publish your changes and enjoy!
Want to add a message or alternative content if you’ve reached the expiration date? Just add the following code onto the dateCheck
conditional statement.
else {
document.getElementById(id).appendChild(expirationMessage); // Set ID to the targeted element
}
The final result should look something like this:
// Checks for condition to be true
if (dateCheck == 1) {
document.getElementById(id).appendChild(message); // Set ID to the targeted element
} else {
document.getElementById(id).appendChild(expirationMessage); // Set ID to the targeted element
}
See the demo on JSFiddle.
Supported Browsers : Chrome, Firefox, Safari, Opera, Edge, IE7+.
The source code can be found on github and is licensed under the MIT license.
Developed by Peter Burdette