Jump to content

Auto refresh webpage but maintain scroll position


Recommended Posts

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

Link to comment
Share on other sites


if you know the position itll be in you can refresh it to an anchor (page.htm#anchorname) but if the user scrolls, itll just scroll back to the same spot over and over and that prolly wouldnt work

this page seems to have the answer though

http://blogs.x2line.com/al/articles/156.aspx

< html>
< title>< /title>
< head>
< script language="javascript">

// function saves scroll position
function fScroll(val)
{
var hidScroll = document.getElementById('hidScroll');
hidScroll.value = val.scrollTop;
}

// function moves scroll position to saved value
function fScrollMove(what)
{
var hidScroll = document.getElementById('hidScroll');
document.getElementById(what).scrollTop = hidScroll.value;
}
< /script>
< /head>

< body onload="fScrollMove('div_scroll');" onunload="document.forms(0).submit()";>
< form>
< input type="text" id="hidScroll" name="a">< /br>
< div id="div_scroll" onscroll="fScroll(this);"
style="overflow:auto;height:100px;width:100px;">

.. VERY LONG TEXT GOES HERE

< /div>
< /form>
< /body>
< /html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...