Jump to content

Auto Refresh and Scroll Position


sb1920alk

Recommended Posts

Nice forum!

 

I'm using a meta refresh tag to automatically refresh a page. This works great except it resets the scroll position all the way up. If I hit the F5 key or click the refresh button, it keeps the current scroll postion. How can I code it to keep the scroll position with an auto-refresh?

 

Thanks!

Link to comment
Share on other sites

As far as i know, you can't. Some googling seems to confirm my thought that javascript is the way to go. My javascript ain't great and i dont have the time right now to play around with it, otherwise i'd put this together for you. You'll need a few things though:

 

1.) Call a function with the body onLoad attribute that will do two things: firstly, check the URL to see if the current scroll position should be altered (see point 3); and set a timeout to call another function after x number of seconds.

2.) Have this function work out where the scroll bar is (see here for a function that'll do that for you)

3.) Reload using javascript, appending the scroll position to the URL (yourpage.php?scroll=whatever)

 

p.s. Welcome to the forum!

 

Link to comment
Share on other sites

Thanks for your response. I haven't had a chance to try your idea. I just now found something else that looks like it will work at first glance. Hopefully my search is over.

 

I encasesed the page in question in a new page's iframe. I set marginheight to 0, scrolling to no, width to 100%, and height to 190% - which fit the lenght of my page, I will probably need to adjust this setting if the page gets longer. Now when it refreshes, it's the iframe that refreshes instead of the page contain the iframe, even though that's all it contains and it's 100%. The only difference I can see is a slightly larger bottom margin, but I can live with that. The iframe is the only thing the new page contains. I'm going to rename the orginal page and name the new page in it's place.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.