Possible to rewrite url clientside with javascript without reloading page

前端 未结 4 520
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-31 06:16

Is it possible to rewrite the URL in the URL-field on the client\'s browser?

So when a person clicks on a link on my page something ajax happens (eg a tab shows up)

4条回答
  •  难免孤独
    2020-12-31 06:52

    URL rewriting is not possible, but it is very common to append action data with a hash. For example, Facebook uses it extensively:

    http://www.facebook.com/#!/username
                            ^
    

    Everything after the hash is just anchor data in the same page, which you can modify by script all day long.

    Newer browsers also offer the onhashchanged event so you can react to the "URL" changing instead of polling it constantly.

提交回复
热议问题