Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4246
  • Last Modified:

Auto refresh webpage but maintain scroll position

I need to automatically refresh webpage every 10 seconds, however i want to maintain scroll position. Unfortunately when using meta refresh or javascript location.reload, page returns to top.

Does anyone know how to do this with javascript or asp

James
0
jambor68
Asked:
jambor68
  • 4
  • 2
2 Solutions
 
b0lsc0ttIT ManagerCommented:
jambor68,

ASP won't be any help for this.  It can't directly cause a refresh.  It can write html or Javascript but not directly work with the browser because ASP is a server language.

Does the whole page need to be refreshed?  If not then you have options like AJAX or frames/iframes.  These can be very easy to implement.

If the whole page then you can't really do it, at least not easily.  You would have to grab the scroll position, which can be with different script depending on the browser and then need to use a cookie to store the value.  It would be the only way to have the new, refreshed page know where the previous was.  Having script set this on the reload is often jerky.

Let me know if you have any questions or need more information.  Hopefully you won't need all of the content refreshed.

b0lsc0tt
0
 
jambor68Author Commented:
b0lsc0tt,

Unfortunately i need to refresh the whole page.

James
0
 
MatthiasVanceCommented:
You could host the page that you need refreshed in a parent page (by using an iframe).
I included some example code.

Another option would be to load the entire contents in PHP and then get the information you need, or you could dynamically load the page into a DIV for example using XmlHttpRequest.

Kind regards,

Matthias Vance
<!-- refresh_scroll_page.php just contains a lot of lines -->
<iframe id="page" src="refresh_scroll_page.php">
</iframe>
<script language="JavaScript">
	setTimeout ("refreshPage()", 3000);
	
	var scrollX = 0;
	var scrollY = 0;
	
	function refreshPage() {
		var page = window.frames['page'];
		scrollX = page.document.body.scrollLeft;
		scrollY = page.document.body.scrollTop;
		page.document.location = "refresh_scroll_page.php";
		setTimeout("doScroll()", 1000);
	}
 
	function doScroll() {
		var page = window.frames['page'];
		page.document.body.scrollLeft = scrollX;
		page.document.body.scrollTop = scrollY;
		setTimeout ("refreshPage()", 3000);
	}
</script>

Open in new window

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
b0lsc0ttIT ManagerCommented:
Why the delete?  What was misunderstood?  It seems from your other response that I understood it correctly and you need the whole page refreshed.  In that case I provide the short answer ("You can't") and even described a way to "fake it" including the issues and limits to trying/doing it.  If this is right then I provided the answer.  Let me know if you have a follow up on it or if I have misread something but otherwise it seems my comment is the answer.
bol
0
 
b0lsc0ttIT ManagerCommented:
MatthiasVance,
It seems like your suggestions build off what I already suggested (an iframe or AJAX).  In that case you should make sure you give credit to the expert when you use their suggestion, even if you are adding to it.
bol
0
 
MatthiasVanceCommented:
Sorry for forgetting to mention you in my post, b0lsc0tt. You are right.

Kind regards,

Matthias Vance
0
 
b0lsc0ttIT ManagerCommented:
Thanks for the fun question.
bol
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now