开发者

Dynamic Links and Ajax

I don't know how to describe this, but I have a website that dynamically loads content using ajax. Therefore, the page is never reloaded and the URL stays the same. I would like th开发者_如何学Goe page to never refresh, but the URL to change, so people can copy and paste the URL and share it. When someone goes to the URL it will auto update the ajax to the content that should be on screen.

Now that was an awful description.

Here's an example:

http://www.phish.com

http://phish.com/#/music/


If you change the url completely even with javascript then in that case the whole page reloads.

You can add parameter after # in url which can act as an identifier for different page.

You can add it as follows -

window.location.href = window.location.href+'#identifier';

as you told that you are loading the page with ajax so you can obtain the identifier from url as follows -

var identifier = window.location.hash;

And so depending on the value of identifier you can load different contents.


You might want to have a look at sammy.js.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜