Detect first page load with jQuery?

后端 未结 4 1663
耶瑟儿~
耶瑟儿~ 2021-02-14 08:15

I need to detect the first time a page loads in jQuery so that I can perform some actions only when the page loads the first time a user navigates to that page. Similar to serve

4条回答
  •  粉色の甜心
    2021-02-14 09:08

    You will have to use cookie to store first load information:

    if (! $.cookie("cookieName")){
       // do your stuff
    
       // set cookie now
       $.cookie("cookieName", "firstSet", {"expires" : 7})
    }
    

    Note: Above example uses jQuery Cookie plugin.

提交回复
热议问题