$(document).ready(function() {
if (sessionStorage.getItem('#myModal') !== 'true') {
$('#myModal').modal('show');
sessionStorage.setItem('#myModal','true');
}
});
This is the code that I use for modal. I want to delay 1 second this modal on page load.
$(document).ready(function() {
var delayMs = 2000; // delay in milliseconds
if (sessionStorage.getItem('#myModal') !== 'true') {
$('#myModal').modal('show');
sessionStorage.setItem('#myModal','true');
}
});
I tried this but it didn't work.
CodePudding user response:
It appears you intended to wrap some of your nested ready
code in a setTimeout
block but missed the actual implementation. See if it works with this:
$(document).ready(function() {
var delayMs = 2000; // delay in milliseconds
setTimeout(() => {
if (sessionStorage.getItem('#myModal') !== 'true') {
$('#myModal').modal('show');
sessionStorage.setItem('#myModal','true');
}
}, delayMs);
});