The problem is that you reload the exact same page so with no way to persist the fact that you already ran that code it will just run it again.
The old-fashioned way of doing this was using cookies:
function timedRefreshIfNoCookie(timeoutPeriod, cookieName) {
var cookies = document.cookie;
if (cookies.indexOf(' '+cookieName+'=1;') < 0) {
document.cookie = cookieName+'=1';
setTimeout(function () {
location.reload();
}, timeoutPeriod);
}
}
window.onload = function() {
timedRefreshIfNoCookie(3000, 'refreshed');
}
document.getElementById('myModal').style.display='block';
You can probably use something a bit better like local storage or a cookie library to work with cookies more easily.