I notice that when I browse pages in Twitter. Instead of having some like twitter.com/home.php?var1=2&asjfaj...etc. (the most common way), the link is just Twitter.com/#home or twitter.com/inbox or twi开发者_Go百科tter.com/followers. my guess is, they use sessions variables to pass information across pages/ links. is it a good way to do it? what are the pros and cons of using session or the url query to pass data across pages?
They're loaded via AJAX. The #home
etc. in the URL allows bookmarking and browser history - if you go to http://twitter.com/#replies
you get the replies page correctly, as their JavaScript code looks for document.location.hash
's value and loads the right page.
Gmail also does this with the document hash, if you want another example.
ajax. lot of ajax!
EDIT
this is what I use to keep a history
<script>
function openOption(opened) {
if (!opened)
var selectedTab = document.location.hash;
else
var selectedTab = opened;
if (selectedTab != null && selectedTab.length > 0) {
selectedTab = (selectedTab[0] == '#') ? selectedTab.substring(1, selectedTab.length) : selectedTab;
if ($(selectedTab)) {
toggleLayer_on(selectedTab);
$(selectedTab).focus();
$(selectedTab).scrollTo();
}
}
}
openOption();
</script>
精彩评论