Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8709553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:23:19+00:00 2026-06-13T04:23:19+00:00

I am trying to save / restore the scrolling location on Postbacks. My code

  • 0

I am trying to save / restore the scrolling location on Postbacks.
My code works for Firefox and all major browsers except for 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;
    }
}

Notice my alert box where I am printing the cookie name.

Firefox prints the following:

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

Internet Explorer prints the following:

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

Notice that the string
KulScrollPos=0,1946;
is being left off the cookie name. This only happens in Internet Explorer!

***I tried another approach at setting the string variable (the line that is commented out) where I am setting document.cookie = … This line also produced the same alert output as displayed above.

Notice my ELSE Block in my RestoreScrollPosition.
The if (matchResult) condition always fails because of this, because of which, my code there where I call my scrollTo method never gets called!

Ughhh, am I concatenating the strings wrong? What doesn’t IE like that FF does?

Very strange behavior indeed!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:23:20+00:00Added an answer on June 13, 2026 at 4:23 am

    Apparently Internet Explorer doesn’t like the “=” (equal sign) in cookie names that is provided within double quotes. It was interpreting the ‘=’; rather than accepting it as a literal; thus, I solved the problem using the single quotes. Apparently, you have to be forceful with IE! Go figure….

    The following code fixed the problem that I was having –

    function saveScrollPosition() {
    
        // Save the cookie if the requesting browser is Internet Explorer
        if (navigator.appName.indexOf("Microsoft") != -1) {
            // Ensure that the cookie will be saved on IE version 5/+
            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;
            document.cookie = 'KulScrollPos =' + scrollX+','+scrollY+';'+document.location.pathname;
        }
    
        // Save the cookie for all other major browsers
        else {
            document.cookie = "KulScrollPos="+f_scrollLeft()+","+f_scrollTop()+"; path="+document.location.pathname;
        }
    }
    

    Lessons learned –

    Don’t use “=” signs in your cookie names. If you need them, use the single quotes to tell IE not to interpret it, but to accept it as a literal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to save a row in my settings table, it works all fine
I'm trying to save some data into an array but unfortunately all the data
I am trying to save multiple image using this code. But instead its saving
I'm trying to save / restore the window size, state and position of a
I am trying to save and restore state by using a StateBlock in SlimDX
I'm trying to save and restore the position of the document within a FlowDocumentReader
We are trying to save the state of the application on exit and restore
Im trying to save a simple script in netbeans to htdocs, but i only
When trying to save the database using boost serialization, I encounter the segfault that
I'm trying to save a CUploadedFile object in local folder, I am using img

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.