[英]How to reload a webpage with a button click in javascript but after reload calling a function
我正在创建一个Flash库,我希望每次在页面上显示新的flash时页面都会重新加载。 我想这样做是因为我希望增加每次用户访问时显示的广告数量。 按钮单击成功重新加载页面但停止将来的代码触发,这是显示闪存的内容。
var c = 0;
var flashcon, test, temp;
// Function for inital flash page to work properly
function init() {
flashcon = document.getElementById('flashcon');
// Scripts for the buttons
document.getElementById('back').onclick = function () {
location.reload(false);
if (c == 0) {
c = paths.length;
}
c--;
displayFiles();
download();
}
document.getElementById('next').onclick = function () {
location.reload(false);
if (c == paths.length - 1) {
c = -1;
}
c++;
displayFiles();
download();
}
document.getElementById('rand').onclick = function () {
location.reload(false);
temp = c;
while (c == temp) {
c = Math.floor(Math.random() * paths.length);
}
displayFiles();
download();
}
// Scripts for the left and right arrow key functionality
document.addEventListener('keydown', function (e) {
if (e.which == 37) {
$("#back").click();
}
});
document.addEventListener('keydown', function (e) {
if (e.which === 39) {
$("#next").click();
}
});
}
在重新加载之前在localStorage中设置一个标志然后在init上检查该值并正常调用你的函数或init。
您需要存储变量。 这可能是你想要的: https : //developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.