如何在重新加载调用函数后,在javascript中单击按钮重新加载页面

时间:2021-05-06 14:29:48

I am making a flash gallery and I would like the page to reload every time a new flash is displayed on the page. I would like to do this because I would like to increase the amount of ads displayed per user visit. The button clicks successfully reload the page but stops the future code from firing which is what displays the flash.

我正在制作一个flash图库,我希望页面每次显示一个新的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();
        }
    });
}

2 个解决方案

#1


2  

Set a flag in localStorage before reload Then on init check the value and call your function or init normally.

在重新加载之前,在localStorage中设置一个标志,然后在init上检查值并正常调用函数或init。

#2


1  

You'll need to store a variable. This is probably what you want: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API

您需要存储一个变量。这可能就是您想要的:https://developer.mozilla.org/en- us/docs/api/web_storage_api

#1


2  

Set a flag in localStorage before reload Then on init check the value and call your function or init normally.

在重新加载之前,在localStorage中设置一个标志,然后在init上检查值并正常调用函数或init。

#2


1  

You'll need to store a variable. This is probably what you want: https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API

您需要存储一个变量。这可能就是您想要的:https://developer.mozilla.org/en- us/docs/api/web_storage_api