Window.onpopstate not trigger properly in Safari

I have to prevent the back button and throughs an alerts it will be working on the Mac environment with browsers are firefox and chrome but safari is not triggering the function .i have been given below snippets.

const neutralizeBack = () => {

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

        window.onpopstate =() =>{

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

            addBody(<RevertAlertModal close={() => hideModal()} />);

                                  showModal("primary");

        };

    }

Hello @Thirumalai

i did not used this api before but did you checked the console in safari and notice if it report any issue

did you tried to use any console.log inside the onpopstate and see if it behave as it expected and if it work then the issue could be related to

addBody(<RevertAlertModal close={() => hideModal()} />);

                                  showModal("primary");

hope that help and have a nice day :slight_smile:

Hey @justsomeone.
Thanks for your reply :grinning:
yeah i tried with console.log within the onpopstate function but it could not be triggered .but we type manually in safari console with command t of window.onpopstate() this will be triggered the inside function of alert.

you welcome @Thirumalai

this what i found

sorry i do not have mac or windows to try safari

hope this link help and have a nice day :slight_smile:

1 Like