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

  • SEARCH
  • Home
  • 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 6349965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:43:13+00:00 2026-05-24T21:43:13+00:00

I am checking, getting and setting a cookie to trace the last visited page.

  • 0

I am checking, getting and setting a cookie to trace the last visited page. And to do this I am calling a Javascript onload. Issue is when I execute this js, it refreshes again and again, very much like a even on mouse movement, but I am not having any event other than onload.

Here is my js:

 <script type='text/javascript'>
    //<![CDATA[
    
    window.onload = function(event){        
        var currentPage = window.location.href;
        var lastVisited = getCookie('udis');
        var sessionId= getCookie('udisSession');
        if(lastVisited === null || lastVisited === undefined){
            setCookie("udis", currentPage, 365);
            lastVisited = getCookie('udis');
        }
        if(sessionId === null || sessionId === undefined){
            setSessionCookie('udisSession');
            if(lastVisited !== currentPage){
                window.location.href = lastVisited;         
            }           
        }
        setCookie("udis", currentPage, 365);
        updateBreadCrumb();
    }
        
        function getCookie(c_name) {
            var i,x,y,ARRcookies=document.cookie.split(";");
            for (i=0;i<ARRcookies.length;i++){
                x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
                y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
                x=x.replace(/^\s+|\s+$/g,"");
                if (x==c_name) {
                    return unescape(y);
                }
            }
        }
        function setSessionCookie(c_name){
        document.cookie=c_name + "=" + 'testSession'+'; expires=; path=/';
    }
        
        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;
        }
      

    //]]>
    </script>

The above code works flawlessly in Firefox but in IE-8 it’s causing the page to reload again and again.

  • 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-05-24T21:43:13+00:00Added an answer on May 24, 2026 at 9:43 pm

    When setting a cookie, you need a space after the semicolon. You also need an expiration date. If you want to make a cookie that expires when the browser closes, then remove the expiration date clause.

    function setSessionCookie(c_name){
        document.cookie=c_name + "=" + 'testSession'+'; path=/';
    }
    

    I suggest you use the functions from here:

    function createCookie(name,value,days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime()+(days*24*60*60*1000));
            var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
    }
    
    function eraseCookie(name) {
        createCookie(name,"",-1);
    }
    

    Instead of using setSessionCookie(c_name), you could use createCookie(c_name, 'testSession');

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

Sidebar

Related Questions

I am checking, getting and setting a cookie to trace the last visited page.
I'm setting a cookie on an anchor click on my page: $(#btn_twitter_signin).click(function() { $.cookie(bookmarklet_twitter_signin,
Is this possible programmatically? Getting the names of stored queries or checking if a
I seem to be getting breakpoints from other programmers when checking out code... Where
When checking an object's identity, I am getting assertion errors because the object creation
I'm getting the following error when I try to install mod_wsgi ./configure checking for
i created a login page in php and used session in it... after checking
I know this is usually done with cookies, but I am getting unpredictable results
I am checking memory allocation in performance tool, i am getting more than 90
I am getting a EXC_BAD_ACCESS (SIGBUS) on this line in my iPhone project: if

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.