User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 423,340 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,164 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 827 | Replies: 4
Reply
Join Date: Jun 2006
Posts: 18
Reputation: asmith3006 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
asmith3006 asmith3006 is offline Offline
Newbie Poster

Maintain Div Postion on Refresh

  #1  
Jun 30th, 2008
Hi,

I have a page which has a Div on it which gets constantly updated (every 1-3 seconds) but I want it to maintain its position between refreshes. I'm very very very new to Javascript and I am finding it very difficult to convert code that I've found online.

Can someone please point me in the right direction? So far the only code I've been able to find requires the code to make the div itself rather than modify an existing div.

Thanks.

Andrew.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Location: Noida, India
Posts: 158
Reputation: Luckychap is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 17
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Junior Poster

Re: Maintain Div Postion on Refresh

  #2  
Jun 30th, 2008
give some id to the div. And by using its id change the content of the div.

HTML:
  1. <div id="mydiv"></div>

javascript:
  1. var mydiv = document.getElementById("mydiv");
  2. mydiv.innerHTML = "Any content that is to be updated.";

If this is not what u were expecting then explain ur problem in more details.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote  
Join Date: Jun 2006
Posts: 18
Reputation: asmith3006 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
asmith3006 asmith3006 is offline Offline
Newbie Poster

Re: Maintain Div Postion on Refresh

  #3  
Jul 1st, 2008
Sorry, I really didn't explain myself very well.

I'm making a chat style system with the newest messages at the bottom. At the moment every time the content is refreshed the div automatically scrolls to the bottom (which is what I want) but, if the user is scrolling up and reading a previous message then it also jumps to the bottom. Obviously it would be better if, when people are scrolling and the page refreshes, it maintains the position of the scroll on the div.

Is that any clearer? I'm not sure..
Reply With Quote  
Join Date: Aug 2006
Location: Noida, India
Posts: 158
Reputation: Luckychap is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 17
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Junior Poster

Re: Maintain Div Postion on Refresh

  #4  
Jul 1st, 2008
if only the div content have to be changed then why u r refreshing whole page(u can use ajax). And to maintain the position while new content is added use textarea instead of div.

what say?
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote  
Join Date: Jul 2008
Posts: 48
Reputation: Ken Sharpe is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
Ken Sharpe's Avatar
Ken Sharpe Ken Sharpe is offline Offline
Light Poster

Re: Maintain Div Postion on Refresh

  #5  
Jul 2nd, 2008
Na, you can just measure. If you use ajax instead of refreshing the whole page, you will have a chance right after the ajaz call is made successfully to check the position of the scroll bar. If it's all the way at the bottom, then add the text, and push the scroll even farther. If it's not at the bottom, then the user is scrolling, so update the text but don't move the scroll bar.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 11:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC