Click here to Skip to main content
15,909,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am setting vertical scrollbar value using "document.documentElement.scrollTop=200;". It is working fine in Firefox and IE but it is not working in Google Chorme.
How to set this value in Google Chrome? Thanks in advance.
Posted
Comments
Kornfeld Eliyahu Peter 13-Jan-14 7:40am    
Can we see you code in context?
prem shanker verma 13-Jan-14 8:00am    
window.onload = SetTop;
function SetTop() {
var verticalTop = document.getElementById('<%=hScrollPosition.ClientID %>').value
document.documentElement.scrollTop = verticalTop;
}
Kornfeld Eliyahu Peter 13-Jan-14 8:18am    
scrollTop isn't W3C standard - even it implemented in most browsers (originally form IE) ,but not Chrome.
The standard property called pageYOffset (not supported in IE < 9) - try it!
prem shanker verma 22-Jan-14 1:08am    
Thanks peter, window.pageYOffset works fine.
Kornfeld Eliyahu Peter 22-Jan-14 2:24am    
Made it into a solution to benefit of all...

The scrollTop property isn't W3C standard - even it implemented in most browsers (originally form IE), but not in Chrome.
The standard property called pageYOffset (not supported in IE < 9) - try it!
JavaScript
window.onload = SetTop;

function SetTop() {
  var verticalTop = document.getElementById('<%=hScrollPosition.ClientID %>').value

  document.documentElement.pageYOffset = verticalTop;
}
 
Share this answer
 
Refer - Cross browser JavaScript (not jQuery…) scroll to top animation[^] and try the technique.

You can also click on the fiddle[^] link given in answer to check the demo.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900