0

Is there a way when Page change location to keep some HTML Element's. Like a div that will not be re-rendered but keep it's state.

You can find and example like that at Facebook Chat ,you can see that the Chat window does not change it's location or InnerHtml when you navigate to another page.

PS : I have no clue where to start so any documentation would be appreciated.And it would be nice if solution would be XHTML not HTML5

Rosmarine Popcorn
  • 10,761
  • 11
  • 59
  • 89
  • 1
    possible duplicate of [How does GitHub change the URL but not the reload?](http://stackoverflow.com/questions/4973777/how-does-github-change-the-url-but-not-the-reload) … and also of http://stackoverflow.com/questions/4952554/github-source-dynamic-navigation which has better answers. – Quentin Apr 18 '12 at 07:26
  • 1
    This *is* part of HTML5. It is called the History API. Without it, it can't happen. – Florian Margaine Apr 18 '12 at 07:47

2 Answers2

-1

When window.location changes, the page is automaticaly, entirely re-rendered. So, from this point of view, the answer is no. However, this effect can be obtained by using AJAX. Use ajax to make requests to the server while the page does not reload or changes location(window.location is always the same). Here's a good link to start with AJAX:

http://www.w3schools.com/ajax/default.asp

If you still want the page to change it's location, after you've made your ajax request and updated the content on the page, you can use javascript's history.pushState function. However you will have to find a way to make it cross browser(aka. make it work in IE).

d4rkpr1nc3
  • 1,817
  • 13
  • 16
  • That isn't true. See the links to the duplicate questions in the comments. Also, please avoid W3Schools, they are [awful](http://w3fools.com/). – Quentin Apr 18 '12 at 07:36
-1

I don't know exactly how facebook chat works, but I do know all chat messages are stored in a database, so you can access them later via messages.

My assumption would be that a Session variable is set letting facebook's UI know what chats you have open, or perhaps its stored in the database as well. In either case, you'd have to use some outside script in order to do this. For sake of ease lets say you'll use PHP, and you'll store the data in a SESSION variable.

/* Storing the variable */
$users = array('user123', 'user456', 'user789');
$_SESSION['chat_windows_open'] = $users;
/* Retrieving the values */
foreach($_SESSION['chat_windows_open'] as $chat) {
/* Use $chat to get the username, query the DB for 
the message content, and echo it in whatever form you
wish. */
}
Wally
  • 106
  • 5
  • No. That would require it to be reloaded with each new page. It wouldn't maintain it's entire state. – Quentin Apr 18 '12 at 07:38