Internet Explorer cookie nicht richtig eingestellt ist, mit JavaScript

Ich versuche zu speichern /wiederherstellen der scrolling Position auf Postbacks.
Mein code funktioniert für Firefox und allen gängigen Browsern außer Internet Explorer.

    function saveScrollPosition() {

    //Save the cookie if the requestor is Internet Explorer
    if (navigator.appName.indexOf("Microsoft") != -1) {
       alert("Internet Explorer browser has been identified...");
       var scrollX, scrollY;
       var strA = "KulScrollPos=";
       var strB = ",";
       var strC = "; path=";

       //Depending on the version of Internet Explorer --- call the appropriate API
       if (!document.documentElement.scrollLeft)
         scrollX = document.body.scrollLeft;
       else
         scrollX = document.documentElement.scrollLeft;
       if (!document.documentElement.scrollTop)
         scrollY = document.body.scrollTop;
       else
         scrollY = document.documentElement.scrollTop;
       alert("scrollX = " + scrollX + " and " + "scrollY = " + scrollY);
       alert("strA = " + strA);

       //document.cookie = "KulScrollPos="+scrollX+","+scrollY+"; path="+document.location.pathname;
       document.cookie = strA.concat(scrollX, strB, scrollY, strC, document.location.pathname);
    }
    //Save the cookie for all other major browsers
    else {
       document.cookie = "KulScrollPos="+f_scrollLeft()+","+f_scrollTop()+"; path="+document.location.pathname;
    }
    alert("cookie = " + document.cookie)
}

function restoreScrollPosition() {
    alert("Entered the restore method...");
    cookieName = "KulScrollPos";

    if (document.title == "KFS :: Create Purchase Log") {
       resetScrollPosition();
       expireCookie( cookieName );
       return true;
    }
    else {
       var matchResult = document.cookie.match(new RegExp(cookieName+"=([^;]+);?"));
       if ( matchResult ) {
         var coords = matchResult[1].split( ',' );
         if (coords[1] != 0) {
           alert("Restoring the scroll position before scrollTo... " + coords[0] + " and " + coords[1]);
           window.scrollTo(coords[0],coords[1]);
           parent.window.scrollTo(coords[0],coords[1]);

        }
        expireCookie( cookieName );
        return true;
    }
    else {
     return false;
    }
}

Beachten Sie meine alert-box, wo ich bin drucken Sie die cookie-Namen.

Firefox druckt die folgenden:

cookie = KulScrollPos=0,1946; kualiSessionId=A7807919-4719-D5B4-91D6-9CC04EEA1BA8;JSESSIONID=1F155C7FC23C48A4DAF557CA4B92D2CB

Internet Explorer druckt die folgenden:

cookie = kualiSessionId=072BE31C-6AF5-6D4C-11A4-55E799790C6A; JSESSIONID=76D83E8E7EBA5F25B8A1B1990B9344E8

Beachten Sie, dass der string
KulScrollPos=0,1946;
wird Links aus dem cookie-Namen. Das passiert nur im Internet Explorer!

***Ich versuchte einen anderen Ansatz, der auf die Einstellung der string-variable (die Zeile, die auskommentiert ist), wo ich die Einstellung Dokument.cookie = ... Diese Zeile auch erzeugt die gleiche Warnmeldung ausgegeben, die oben dargestellt ist.

Beachten Sie meine ANDEREN Block in meinem RestoreScrollPosition.
Die wenn (matchResult) Zustand schlägt immer fehl, weil dieser, weil von denen, mein code dort, wo nenne ich mein scrollTo Methode wird nie aufgerufen!

Ughhh, bin ich die Verkettung der strings falsch? Was nicht IE wie FF?

Sehr seltsam Verhalten, in der Tat!

InformationsquelleAutor ivan_drago | 2012-10-17

Schreibe einen Kommentar