Search code examples
javascriptasp.netscroll-position

how Can retrieve scroll Position in page that have an iframe in it


My code does not work in page that have iframe in it (document.cookie) change! after postback! the code is:

$(window).scroll(function() {
oldScroll = $(this).scrollTop();
if (oldScroll >15) {
document.cookie = pathname + oldScroll+'@'; }
}); 

$(window).load(function() {
load();
}); 

function load() {
var pathname = window.location.pathname;var newScroll;
var starPos = document.cookie.indexOf('aspx')+4;
var endPos = document.cookie.indexOf('@');
newScroll = document.cookie.search(";");
var oldPage=document.cookie.substring(0,pathname.length);
$(window).scrollTop(document.cookie.substring(starPos, endPos));
} 

Solution

  • I find the answer and i can get back scroll in page postback

    $(document).ready(function () {
    var pathname = window.location.pathname;
    $(window).ready(function () {
        $(this).scroll(function () {
            oldScroll = $(this).scrollTop();
            if (oldScroll > 100) {
                setCookie("scroll", pathname + oldScroll + "@", '2020');
            }
        });
    });
    
    
    $('#tabContainer').load(function () {
        load();
    });
    });
    
    
    function load() {
    var pathname = window.location.pathname;
    var newScroll;
    var starPos = document.cookie.indexOf("aspx") + 4;
    var endPos = document.cookie.indexOf("@") ;
    
    if (endPos != -1 && starPos != -1) {
        $(window).scrollTop(document.cookie.substring(starPos, endPos));
    }
    }
    
    function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
    }