结合mousemove和mouseaction脚本

时间:2017-11-29 01:34:57

标签: javascript html html5

我正在构建一个包含iframe的网站,并且如果用户在特定时间段内未使用鼠标,则会将脚本重定向到其他网站。此计时器将重置鼠标操作:

function countdown(outputElement, seconds) {
    var s = 27,
        bs = 27;
    if (seconds) {
        s = bs = seconds;
    }

    function tF() {
        outputElement.innerHTML = s = bs;
        return setInterval(function () {
            s--;
            if (!s) {
                s = true;
                clearInterval(timer);
                window.open('http://example.com');
            }
            outputElement.innerHTML = s;
        }, 1000);
    }
    var timer = tF();
    onmousemove = function () {
        clearInterval(timer);
        timer = tF();
    }
}
var old = onload;
onload = function () {
    if (old) old();
    countdown(document.getElementById('counter'));
}

但是,我也有一个鼠标点击脚本,也就是说,每次点击iframe时,它都会将用户发送到与空闲计时器相同的页面(在这种情况下,它会打开一个新窗口http://example.com ):

document.addEventListener('click', clickeable);

function clickeable() {
    window.open('http://example.com');
    window.close();
}

如果选项卡是通过脚本打开的,它会自行关闭,并指向这个新选项卡。

我的问题是,我想把这两个行动结合起来,但由于我对这个问题太新了,所以没有运气。 我的要求是:   - 脚本运行一个计时器,每次鼠标移动时都会重置,如果它达到0,它会打开一个新窗口,理想情况下会自行关闭。 - 如果用户在iframe上点击,该操作将打开一个新窗口并理想地自行关闭,但它会使计时器停止执行同样的操作。

我猜这需要一个IF和OR条件,但我似乎无法让它工作。我坚持我的计时器脚本和我的鼠标脚本打开具有相同内容的新标签这一事实。

这是我网站的临时链接,以防对某人有用:

http://unnameable.world

0 个答案:

没有答案