Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Set a flag in the cookie and when the page loads check that cookie for the state

    I have this javascript function which I need somehow to be remembered by cookies.

    function load(){


    if (window.frames[0].document.getElementById('applications'))
    {
    var n=str.replace("Login","Logout");
    document.getElementById('common').href='../css/common2.css';}}
    I understand I need to set a flag in the cookie and when the page loads check that cookie for the state.

    So, cookies script is :

    function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    if (exdays) exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays) ? '; expires=' + exdate.toUTCString() : '');
    document.cookie = c_name + "=" + c_value;
    }

    function getCookie(name) {
    var re = new RegExp(name + "=([^;,]+)");
    var value = re.exec(document.cookie);
    return (value !== null) ? unescape(value[1]) : null;
    }
    I have problems setting the flag in the cookie and check for cookie state.

    if (window.frames[0].document.getElementById('applications')
    && !getCookie('authentication'))
    {
    var n=str.replace("Login","Logout");
    document.getElementById('common').href='../css/common2.css';
    setCookie('authentication','1',1);}

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    3,772
    Thanks
    23
    Thanked 550 Times in 549 Posts
    Good page to read and get code:
    http://www.w3schools.com/js/js_cookies.asp
    Evolution - The non-random survival of random variants.


  •  

    Posting Permissions

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