Monday, 10 March 2014

create cookies using javascript

/*-----( CREATING COOKIE )------*/

 var email =$('#txtUserName').val();
 var pwd = $('#txtPassword').val();
 var d = new Date();
    d.setTime(d.getTime()+(30*24*60*60*1000));
     var v_rememberMe = $('#RememberMe').is(':checked') == true ? "Y":"N";
    $('#RememberMe').is(':checked') == true ? (document.cookie = "email=" + email + ";expires=" + d.toGMTString() + "") : d.setTime(d.getTime() + (-31 * 24 * 60 * 60 * 1000)); document.cookie = "email=" + email + ";expires=" + d.toGMTString() + "";

/*-------( GETTING COOKIE VALUES )--------*/
$(document).ready(function () {

    var mail = getCookie("email");
    var expdays = getCookie("expires");
 
   // mail!= "" ? ($('#txtPassword').focus(); $('#txtUserName').val(mail)): $('#txtUserName').focus();
    if (mail != "") {
        $('#txtPassword').focus(); $('#txtUserName').val(mail); $('#RememberMe').attr('checked', true);
    }
    else { $('#txtUserName').focus(); }
});
/*----( Getting cookie by Name )----*/
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
}

No comments:

Post a Comment

Extracting Nupkg files using command line

Rename it to zip first then extract files as below 1.     Rename-Item -Path A_Package.nupkg -NewName A_Package.zip 2.     Make sure to repla...