Results 1 to 3 of 3

Thread: How do you redirect a return visitor?

  1. #1
    Join Date
    Aug 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do you redirect a return visitor?

    Is it possible to create a cookie using javascript that will redirect a return visitor to the page last viewed? For example if a user completes only half of a 20 page tutorial then quits the browser. When he returns, can he be redirect to where he left off?

  2. #2
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Check out this:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function getCookieVal (offset) {
    
        var endstr = document.cookie.indexOf (";", offset);
    
        if (endstr == -1) {
            endstr = document.cookie.length;
        }
    
        return unescape(document.cookie.substring(offset, endstr));
    }
    
    function getCookie (cookieName)  {
    
        var arg = cookieName + "=";
        var argLength = arg.length;
    
        var cookieLength = document.cookie.length;
    
        var i = 0;
    
        while (i < cookieLength)  {
            var j = i + argLength;
    
    
            if (document.cookie.substring(i, j) == arg) {
    
                return getCookieVal(j)
            }
    
            if (i == 0) {
                break
            }
         }
         return null;
    }
    
    function setCookie(name, value) {
    
    
        var argv = setCookie.arguments;
    
        var argc = setCookie.arguments.length;
    
        var expires = (argc > 2) ? argv[2] : null;
    
        var path = (argc > 3) ? argv[3] : null;
    
        var domain = (argc > 4) ? argv[4] : null;
    
        var secure = (argc > 5) ? argv[5] : false;
    
        document.cookie = name + "=" + escape(value) +
            ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
            ((path == null) ? "" : ("; path=" + path)) +
            ((domain == null) ? "" : ("; domain=" + domain)) +
            ((secure == true) ? "; secure" : "");
    }
    
    function register(userName, value) {
    
        if (userName == "" || userName == null) {
    
            userName = "Unknown User"
        }
    
    
        if(getCookie('myCookie') == null) {
    
            var expdate = new Date()
    
            expdate.setTime(expdate.getTime() + (1000 * 60 * 60 * 24 * 365));
    
            setCookie('myCookie', userName, expdate);
            alert ("Thank you for registering, " + userName + "!  Click OK to enter the registered portion of my site.");
    
             location.href = "list0602.htm"
    
         }
    }
    if(getCookie('myCookie') != null) {
        location.href="list0602.htm"
    }
    </script>
    </head>
    <body>
    <form name="loginForm">
    <input type="text" name="fullName" size=35>
    <br>
    <input type="button" value="Register" onclick="register(loginForm.fullName.value)">
    </form>
    </body>
    </html>
    - Mike

  3. #3
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Did the above work for you? I'm intending to implement a Here's What's New Since Your Last Visit page

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •