вы можете использовать печенье это пример
function executeOnce() {
var argc = arguments.length, bImplGlob = typeof arguments[argc - 1] === "string";
if (bImplGlob) { argc++; }
if (argc < 3) { throw new TypeError("executeOnce - not enough arguments"); }
var fExec = arguments[0], sKey = arguments[argc - 2];
if (typeof fExec !== "function") { throw new TypeError("executeOnce - first argument must be a function"); }
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { throw new TypeError("executeOnce - invalid identifier"); }
if (decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) === "1") { return false; }
fExec.apply(argc > 3 ? arguments[1] : null, argc > 4 ? Array.prototype.slice.call(arguments, 2, argc - 2) : []);
document.cookie = encodeURIComponent(sKey) + "=1; expires=Fri, 31 Dec 9999 23:59:59 GMT" + (bImplGlob || !arguments[argc - 1] ? "; path=/" : "");
return true;
}
Использование
executeOnce (обратный вызов [, thisObject [ , argumentToPass1 [, argumentToPass2 [, ... [, argumentToPassN]]]]], идентификатор [, onlyHere])
function reloadPage() {
var url = window.location.href;
var hash = url.substring(url.indexOf('#')+1);
if(hash == 'add') {
$(window).load(function(){
location.reload();
});
}
}
executeOnce(reloadPage, null, "", "idPage");
не будет ваша страница просто обновляется бесконечно, если вы не удалите хэш при перезагрузке? – timothyclifford
Вы можете использовать 'setTimeout (function() {// code here}, 2000)' – CMedina
Если это не обязательно должен быть точно такой же URL-адрес, вы можете добавить параметр запроса и обновить только, если его нет , Поэтому вместо 'location.reload();' write 'location.href = location.href +"? Foo = bar "'. –