CSS Scroll Position After Javascript "reload()"

R

Raffi

Hi,

I have an application screen with a CSS scroll area. Users click links
in the scroll area which open small popup windows to enter data. When
the data is submitted, the popup reloads the opener to update the page
and closes itself. However when the parent page is updated, the div
scrolls back to the top. Is there a way to have CSS remember the
vertical scroll position and go back to it when the page is reloaded?
Similar to document.body.scrollTop in Javascript. Here's the relevant
portion of the code:

<STYLE TYPE="text/css">
div.scroll
{
height: 400px;
width: 960px;
overflow: auto;
border: 1px solid #0000ff;
background-color: #77ddcc;
padding: 8px;
}
</STYLE>

.............

<div class="scroll">
...application data...
...application data...
...application data...
...application data...
</div>
 
B

Ben C

Hi,

I have an application screen with a CSS scroll area. Users click links
in the scroll area which open small popup windows to enter data. When
the data is submitted, the popup reloads the opener to update the page
and closes itself. However when the parent page is updated, the div
scrolls back to the top. Is there a way to have CSS remember the
vertical scroll position and go back to it when the page is reloaded?
Similar to document.body.scrollTop in Javascript.

I don't think there is a CSS-only way.

You can do this with fragment urls if it's the main document we're
scrolling. If somewhere near the link they clicked you put

<a name="foo"></a>

And then have the popup reload the page using url#foo. They won't be
exactly where they were, but somewhere near it. Might not work in all
browsers.

But in your case, we're talking about a div with overflow: scroll. You
can experiment with fragments, I don't know if that will work.

Can you even get the scroll offset with JS for elements other than body?
 
R

Raffi

Ben said:
I don't think there is a CSS-only way.

You can do this with fragment urls if it's the main document we're
scrolling. If somewhere near the link they clicked you put

<a name="foo"></a>

And then have the popup reload the page using url#foo. They won't be
exactly where they were, but somewhere near it. Might not work in all
browsers.

But in your case, we're talking about a div with overflow: scroll. You
can experiment with fragments, I don't know if that will work.

Can you even get the scroll offset with JS for elements other than body?

Thanks, I'll try that. Unfortunately JS scroll seems to apply to the
body of the page only.

Raffi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top