www.webdeveloper.com
Results 1 to 5 of 5

Thread: Cookie does seem to function

  1. #1
    Join Date
    Aug 2005
    Posts
    59

    Question Cookie does seem to function

    Hi!

    I have a cookie which will jump over the opening index.htm file provided I have been there during the past 24 hours and instead go to "chapter_1e.htm" or "chapter_1.htm" depending on where I was last.

    The cookie seems to function when I am inside the system with all the files but when I start from outside I will wrongly come to the index.htm file page. Cannot the system find the cookie or what can be the reason?


    cookie.js

    var expDate = new Date();
    expDate.setTime(expDate.getTime()+365*24*60*60*1000/365); // one day

    function setCookie(isName,isValue,dExpires,lang){

    document.cookie = isName+"="+isValue+";expires="+dExpires.toGMTString();
    window.open("/"+lang+".htm");
    }

    function getCookie(isName){

    var cookieStr = document.cookie;
    var startSlice = cookieStr.indexOf(isName+"=");
    if (startSlice == -1){return false}
    var endSlice = cookieStr.indexOf(";",startSlice+1)
    if (endSlice == -1){endSlice = cookieStr.length}
    var isData = cookieStr.substring(startSlice,endSlice)
    var isValue = isData.substring(isData.indexOf("=")+1,isData.length);
    return isValue;
    }

    function dispCookie(isName){

    var nValue = getCookie(isName);
    alert(nValue);
    }

    function deleteCookie(isName){

    if (getCookie(isName)){document.cookie = isName + "="+"; expires=Thu, 01-Jan-70 00:00:01 GMT";}
    }

    function init(){

    var currLang = getCookie('myCookie');
    //alert(currLang);
    if (currLang && currLang == 'english'){window.open("chapter_1e.htm")}
    if (currLang && currLang == 'swedish'){window.open("chapter_1.htm")}
    }

    window.onload=init;




    The index.htm file contains the script between the <head> tags.

    <html>
    <head>
    <script src="cookie.js"></script>
    </head>
    </html>


    Can someone explain and help me?

    Kind regards,

    Jan

  2. #2
    Join Date
    Aug 2005
    Posts
    59

    Smile Correction

    Hi!

    The heading was, of course, wrong.

    It should be:
    Cookie does not seem to function.

    Kind regards,

    Jan

  3. #3
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    window.open is likely to be blocked unless it is called as the result of a user-action.

    Try:
    Code:
    location.href ="chapter_1.htm";
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  4. #4
    Join Date
    Aug 2005
    Posts
    59

    Cookie does not seem to function

    Hi!

    Where should I put in your statement in the programme?

    I am not so familiar with javascript.

    Kind regards,

    Jan

  5. #5
    Join Date
    Aug 2005
    Posts
    59

    Question Script does function from inside

    Hi!

    The above script functions when index.htm is called from inside , i.e. when I work with files belonging to www.xxxx.com. Instead of open the index.htm page, you are directed to chapter1e.htm or chapter1.htm, when you click on index.htm, which is the objective.

    However, when you start www.xxxx.com from outside by clicking you will open the index.htm page, even if you have visited the page only a short time before. The purpose was of course to open chapter1e. or chapter1, directly, provided you have visited the index.htm page during the last 24 hours.

    My question is if the reason is a mistake in the programming or if the reason is security settings of the computer? www.xxxx.com is shown as a secure page in my settings.

    Kind regards,

    Jan

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles