当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Setting window.pageYOffset in Firefox doing nothing?

问题描述:

I'm using the most recent version of Firefox.

I'm just trying to get the window to scroll back to the position it was before submitting a form.

In the html head of the page there's the code:

if (sessionStorage.top !== null) {

window.pageYOffset = sessionStorage.top;

}

and later a validation function is called that has the following line in it:

sessionStorage.top = window.pageYOffset;

Since this function submits a form the page is automatically reloaded.

I've verified that the validation function is called, executing all the way through including the line above.

I've verified that the code in html head is being executed (including inside the if statement - sessionStorage.top is not null.

I've verified that both sessionStorage.top and window.pageYOffset are set to 630.

Yet the window stays at position 0 (zero).

I've tried setting window.pageYOffset directly to 630 and this also does nothing. The page stays at the topmost (default) position.

What am I missing?

网友答案:

Because it is readonly? Use window.scrollTop = offsetValue; to set the scroll position.

分享给朋友:
您可能感兴趣的文章:
随机阅读: