sb1920alk Posted January 9, 2008 Share Posted January 9, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/85216-auto-refresh-and-scroll-position/ Share on other sites More sharing options...
GingerRobot Posted January 9, 2008 Share Posted January 9, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/85216-auto-refresh-and-scroll-position/#findComment-434759 Share on other sites More sharing options...
sb1920alk Posted January 9, 2008 Author Share Posted January 9, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/85216-auto-refresh-and-scroll-position/#findComment-434812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.