I have implemented Bootstrap 5 toasts to showcase an advertisement on my website. The goal is to make the advertisement disappear for 24 hours once the user closes it.
Here's the current code snippet:
<div class="position-sticky bottom-0" style="z-index: 5">
<div class="toast hide text-center text-white bg-primary border-0" id="cbAd" role="alert" aria-live="assertive" aria-atomic="true" style="width: 100%; border-radius: 0;">
<div class="toast-header">
<strong class="me-auto">Ad</strong>
<small>Website.com</small>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body" style="transform: rotate(0);">
This is the advertisement text.
<div class="mt-1"><a class="btn btn-success stretched-link" href="">Buy Something</a></div>
</div>
</div>
</div>
Javascript:
var option = {
animation: true,
autohide: false
};
function cbToast( ) {
var toastElementHTML = document.getElementById( 'cbAd' );
var toastElement = new bootstrap.Toast( toastElementHTML, option );
toastElement.show();
}
setTimeout(cbToast, 5000);
Is there a way to achieve this using local storage?