Javascript - 重定向到特定页面和从特定页面重定向

时间:2018-01-22 20:31:14

标签: javascript jquery wordpress

这里是Javascript的新手。

我正在我的商店为客户创建一个触摸屏终端,我需要终端在空闲时间之后重定向回主页,因为客户可能会通过网站而不是将其带回主页面他们自己。

jQuery(document).ready(function( $ ){
  
  

var idleTime = 0;
$(document).ready(function () {
    //Increment the idle time counter every minute.
    var idleInterval = setInterval(timerIncrement, 1000); // 1 second

    //Zero the idle timer on mouse movement.
    $(this).mousemove(function (e) {
        idleTime = 0;
    });
    $(this).keypress(function (e) {
        idleTime = 0;
    });
  $(this).scroll(function (e) {
        idleTime = 0;
    });
});
 function timerIncrement() {
    idleTime = idleTime + 1;
     if ((idleTime > 9) && (myPath === '/wp/'))   { // 10 seconds
       window.location.href = "http://localhost/wp";
    } else if ((idleTime > 9) && (myPath === '/wp/juice-intro/')) {
      window.location.href = "http://localhost/wp/juice-intro"; }
 
}

  });

问题是/ wp /上的'View Products'按钮转到/ wp / store /,而/ wp / juice-intro /上的'View Products'按钮转到/ wp / store / Juice-c26616346。 除此之外的问题是,点击过这些页面的每个产品都是/ wp / store / My-Product-a329834

所以我需要一种存储某种值的方法来记住每个终端最初加载的页面。

2 个答案:

答案 0 :(得分:1)

在Chrome中,您可以使用

返回当前浏览器标签打开的第一页
window.history.go( 1 - window.history.length );

答案 1 :(得分:0)

据我所知,您需要从/ wp / store / My-Product-a329834页面导航回上一页才能执行此操作,您可以尝试使用document.referrer

if (idleTime > 9 )   { // 10 seconds
       window.location.href = document.referrer;
    }
相关问题