如何通过 javascript 中的按钮单击重新加载网页,但在重新加载后调用函数
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 中设置一个标志然后在初始化时检查该值并正常调用您的函数或初始化。
您需要存储一个变量。这可能是您想要的:https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API
我正在制作一个 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 中设置一个标志然后在初始化时检查该值并正常调用您的函数或初始化。
您需要存储一个变量。这可能是您想要的:https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API