Detect if page is load from back button

后端 未结 7 840
无人及你
无人及你 2021-02-06 23:07

Is there any way to detect if current page came from back button?

I want to load data from cookie only if current page came from back button.

7条回答
  •  别跟我提以往
    2021-02-06 23:58

    Use pageshow event to detect back or forward buttons:

    $(window).bind("pageshow", function(event) {
        if (event.originalEvent.persisted) {
            Alert("User clicked on back button!");
        }
    });
    

    For more details you can check pageshow event in here .

提交回复
热议问题