How to Detect Browser Back Button event - Cross Browser

后端 未结 16 3201
鱼传尺愫
鱼传尺愫 2020-11-21 23:09

How do you definitively detect whether or not the user has pressed the back button in the browser?

How do you enforce the use of an in-page back button inside a sin

16条回答
  •  庸人自扰
    2020-11-22 00:08

    In javascript, navigation type 2 means browser's back or forward button clicked and the browser is actually taking content from cache.

    if(performance.navigation.type == 2)
    {
        //Do your code here
    }
    

提交回复
热议问题