Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an event like hashchange for query strings?

I have been using hashes to pass data between pages (like setting scrollTop(), etc.) and have also used the hashChange event to trigger changes on a given page.

However, hashes have default behaviors that I'm not necessarily interested in, like making the page jump to a given (sometimes insignificant) spot.

I feel like getting/setting a query string would be more logical, but:

  1. Is it?

  2. Is there an event I can listen for when the query string is set?

  3. Are there query-string-related behaviors I should know about?

like image 237
Isaac Lubow Avatar asked Nov 27 '10 09:11

Isaac Lubow


People also ask

How do you trigger a Hashchange event?

The hashchange event is fired when the fragment identifier of the URL has changed (the part of the URL beginning with and following the # symbol).

How does query string pass information?

To pass in parameter values, simply append them to the query string at the end of the base URL. In the above example, the view parameter script name is viewParameter1.

What is Onhashchange?

The onhashchange event occurs when there has been changes to the anchor part (begins with a '#' symbol) of the current URL. An example of what an anchor part actually is: Assume that the current URL is. http://www.example.com/test.htm#part2 - The anchor part of this URL would be #part2.


1 Answers

As the other answer says, changing the query string will cause a page reload. As far as the browser is concerned you'll then be on a completely new page.

There are events that will fire when you do this. The ’beforeunload` event will fire, however it won't be very useful as it also fires when the user clicks on a link or closes the window.

Effectively the event that will fire if you change the query string will be the load event on the new page that it loads.

like image 130
andynormancx Avatar answered Oct 19 '22 03:10

andynormancx