483
Views
2
Comments
Browser Back button

I am having a requirement where i want to catch browser back button event and show them feedback message and also dont allow them to navigate.


Some of the solutions i got are this:-

1.

window.history.pushState(null, "", window.location.href);

window.onpopstate = function () {

    window.history.pushState(null, "", window.location.href);

};

2.

history.pushState(null, null, location.href);

    window.onpopstate = function () {

        history.go(1);

    };


But my application is little different.

I am having 3 web blocks in same page which i am displaying as per visibility control.

This solutions are directly refreshing my page, i dont want that.


Please help me out with this!

2023-01-05 17-39-49
Leonardo Pires
Champion
2024-04-18 08-00-54
Mayur Shrirame

Hi Kunal, 

I have implemented it in vanilla JS. I am attaching the JS code snippet image. You can go through it for the reference.

Thanks,

Mayur

JSCustom.png
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.