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:

  • Is it?

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

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


  • It is illogical to reinvent anchor behaviour. It is better to not expose hash links to insignificant fragments (although modern browsers are doing scrollIntoView() for any element with id , there is a dedicated behaviour for <a name="xxx"> ). So, answer is yes here, page arguments should be passed via querystring.
  • Event is window.beforeunload , yes, page reload when javascript:void(location.search='some') has been set
  • There are no surprises, have a look
  • Also, on working with querystring: http://xkr.us/js/querystring


    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.


    It depends on what you're doing.

    A query string change will always trigger a page reload. The only part of the URL you can change without a page reload is the #-part.

    In javascript applications, page loads are generally not okay. But it may be possible to use when having a traditional html page request/response model.

    There's no event AFAIK though, since it will change page.

    链接地址: http://www.djcxy.com/p/3892.html

    上一篇: 从XNA到Facebook发布WP7游戏成就

    下一篇: 是否有像查询字符串hashchange事件?