1

Is there a way to detect the page's url change without using onhashchange? Because the url I'm trying to detect does not contain a hash. I tried add a listener on the window, like below, but it did not work. Many thanks!

 <script type="text/javascript">

 window.addEventListener("onpageshow", myFunction); //this does not detect url change for me
    function myFunction() {   
    console.log("url  changed " );
    }
  </script>

1 Answer 1

1

The URL changes when a new document is loaded, you can listen to the unload event of the current document to learn when that happens.

<body onunload="myFunction()">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.