Change URL from Javascript like facebook does

前端 未结 3 501
栀梦
栀梦 2021-01-01 06:09

I\'m currently working in a AJAX oriented web application. I have been looking for the different ways of replicating the current AJAX state (or Application state) with the b

相关标签:
3条回答
  • 2021-01-01 06:15

    There is a feature of HTML5 that supports what you are referring to. See http://spoiledmilk.dk/blog/html5-changing-the-browser-url-without-refreshing-page.

    Some systems implement this by checking for window.history.pushState, and if so, using it, otherwise falling back to hashtags. If SEO is of concern, use #! instead of #. See http://code.google.com/intl/es/web/ajaxcrawling/docs/getting-started.html.

    Hope that helps.

    0 讨论(0)
  • 2021-01-01 06:16

    You are able to manipulate the has value at the end of the URL like this:

    var hashVal = 'somevalue';
    window.location.hash = '#' + hashVal;
    

    And then the url will become www.something.com/#somevalue

    0 讨论(0)
  • 2021-01-01 06:19

    You can manipulate the hash value as Neal pointed out. But i would recommend using a library for doing the same. Here's one that i use

    http://developer.yahoo.com/yui/history/

    Hash values in the URL are manipulated mainly for back button and bookmark integration. Hope this helps.

    0 讨论(0)
提交回复
热议问题