For web applications we are at times required to get the current vertical window scroll bar position.
One of the common way to detect it is by using Javascript with out any external plugin function. We can use below javascript function where we can get the window scroll bar position.
function getScrollXY() { var x = 0, y = 0; if( typeof( window.pageYOffset ) == 'number' ) { // Netscape x = window.pageXOffset; y = window.pageYOffset; } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { // DOM x = document.body.scrollLeft; y = document.body.scrollTop; } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { // IE6 standards compliant mode x = document.documentElement.scrollLeft; y = document.documentElement.scrollTop; } alert('Vertical scroll position: ' + y); }
But when your application runs in Safari 7.0.1 the above function is unable to get the scroll bar position. We can use a JQuery function scrollTop() to get the vertical scroll top position. You need to include the JQuery min js file in your web page and modify the above Javascript function as given below and call this Javascript function in any button it will alert the window vertical scroll top position
function getScrollXY() { var x = 0, y = 0; if( typeof( window.pageYOffset ) == 'number' ) { // Netscape x = window.pageXOffset; y = window.pageYOffset; } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { // DOM x = document.body.scrollLeft; y = document.body.scrollTop; } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { // IE6 standards compliant mode x = document.documentElement.scrollLeft; y = document.documentElement.scrollTop; } /*In Safari 7.0.1 above functions will not work to get vertical scroll top. So if its unable to get vertical scroll top then try to get vertical scroll in jquery $(window).scrollTop() */ if(y == 0){ y = $(window).scrollTop(); } alert('Vertical scroll position: ' + y); }