1

first, please check this url: Shopify variant options

and when you change the variant dropdown option, the current url will be changed with different variant value.

I tried onpopstate event and Location hash event, but all of them is NOT working , as I know they only work for the url format like: /#!/, but the above shopify link using "?"

Anyone knows how it can change url without reload page ? and how I can create an event when url changed ?

Fresh Lover
  • 470
  • 1
  • 8
  • 26
  • Possible duplicate-- does this post answer your question? [How do I modify the URL without reloading the page?](https://stackoverflow.com/questions/824349/how-do-i-modify-the-url-without-reloading-the-page) – Alexander Nied Oct 08 '21 at 04:45
  • thank you , but the link is telling me how I can modify url, but I do not know how I can get a callback event when url changed – Fresh Lover Oct 08 '21 at 04:49
  • You don't need a callback event when URL changed. If the URL get changed by user, the web page will reload; If the URL is changed by you programatically, you just call the action you want after you change the URL. – Ricky Mo Oct 08 '21 at 05:20
  • for sure, the web page will NOT be reloaded, and you also can not get current url via window.location.href which will be a previous (history) url. I wish I can get current url not previous or history url. – Fresh Lover Oct 08 '21 at 05:25
  • If you change the URL programmatically, you already know the URL in the first place. – Ricky Mo Oct 08 '21 at 05:30
  • You are like saying "I want to do `let a = 1` and want to listen to the event when `a` is changed and get the new value of `a`". This is totally redundant because you yourselves assigned `1` to `a` so sure you know `a` is changed to `1`. – Ricky Mo Oct 08 '21 at 05:33
  • this website is not programmed by me, they load too many js so that it is difficult to check one by one, if I can directly create an event , that will be best way, I also want to study for this part. – Fresh Lover Oct 08 '21 at 05:34

0 Answers0