【问题标题】:Mark a page as visited, and forward to the correct part of the code depending on whether it has been visited or not?将页面标记为已访问,并根据它是否已被访问而转发到代码的正确部分?
【发布时间】:2014-07-22 03:54:02
【问题描述】:

我什至不确定如何正确使用标题。我正在寻找一种方法来将页面设置为在加载时访问,然后运行命令。下次我加载网页时,它将被标记为已访问,因此它将执行另一段代码。

例子:

    (function(){
//Detect if page is visited, and direct it to the correct part of the code

//This is the set of code to run if the page has not been visited, Set page as visited here
   $( "#button" ).click(); 

//Run this if the page has been marked as visited
   setTimeout(function(){
  window.close();
}, 50);

})();

对 Jquery 等还是比较陌生,请原谅我的无知。

【问题讨论】:

    标签: jquery userscripts visited


    【解决方案1】:

    在网站的多个视图中存储信息的常用方法是使用 cookie。您可以有一个 cookie 来跟踪该页面是否已被访问。 Cookie 是用户计算机的本地文件,因此效果应该是您想要的。

    这是一个不错的小 cookie 实用程序:

    https://github.com/carhartl/jquery-cookie

    您可以使用它来跟踪该站点是否已被访问,然后您的代码可以检查其值并根据其值执行不同的代码。

    【讨论】:

    • 这是有道理的,但我可能需要一点时间来理解如何完全实现它。我会稍微阅读一下文档,谢谢!
    • 我想你会惊讶于它是多么的简单。试一试,如果您有任何更具体的问题,请随时回来。
    猜你喜欢
    • 1970-01-01
    • 2010-12-29
    • 2011-12-10
    • 2016-12-23
    • 1970-01-01
    • 2010-10-22
    • 1970-01-01
    • 2014-06-18
    • 1970-01-01
    相关资源
    最近更新 更多