Can I detect when a user gets to a page using the back button?

前端 未结 4 794
無奈伤痛
無奈伤痛 2021-01-11 20:37

Edit: What I really need to know is if there is any javascript event that will reliably fire when the user arrives at the page via the back button. I trie

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-11 21:03

    Yes. In javascript you can use visited.value

    function checkrefresh()
     var visited = getCookie("visited");  
    {
            if((form.visited.value == '' || form.visited.value == null) && (visited != '1') ) 
            {
                document.form.visited.value = "1";
                        document.cookie = "visited=1";
                        //here you set it to something so that next time they go to the page it will no longer be nothing and you can 'disable the button' see below.
    
            }
            else
            {
                document.form.submitbutton.disabled=true;
            }
        } 
    
    function getCookie(name)
    {
    var re = new RegExp(name + "=([^;]+)");
    var value = re.exec(document.cookie);
    return (value != null) ? unescape(value[1]) : null;
    }
    

    you would call this in the onload tag FYI.

提交回复
热议问题