简体   繁体   中英

Key Value pair for cookies

I am having an image icon which on clicking should navigate to the other page

  '        <input type="image" id="dataReview_' + templates[i].dataFileKey + '" title="Data Review" src="Images/datareview.png" style="height: 15px; width: 15px" onclick="dataReview_tasks(this); return false;"/>\n' +

In dataReview_tasks() function below

 function dataReview_tasks(inputOb)
    {
   var info = new IOInfo(inputObj);
   var id = info.key(0);
   var tdLastDateId = "lastRun_" + id;
   var decoded_lastRunDate = decodeURIComponent(trim($("#" + tdLastDateId).text())).split(" ")[0];
   var lastRunDate = encodeURIComponent(decoded_lastRunDate);
   window.location('<%= ResolveUrl("~/GUI/DataReviewNEW.aspx") %>');

I should be making the ID and the lastRunDate as cookies. How can I approach this.

在此处输入图片说明

I am not sure why it is not holding the value 54 while I am debugging, I am new Javascript and not sure if I am giving them properly in document.cookie Any help is greatly appreciated

I should be making the ID and the lastRunDate as cookies. How can I approach this.

function dataReview_tasks(inputOb){
    var info = new IOInfo(inputObj);
    var id = info.key(0);
    var tdLastDateId = "lastRun_" + id;
    var decoded_lastRunDate = decodeURIComponent(trim($("#" + tdLastDateId).text())).split(" ")[0];
    var lastRunDate = encodeURIComponent(decoded_lastRunDate);

    var tCookiename = '<%= this.CookieDataFileKey %>'; //This is your '$DataFileKey' placeholder from codebehind
    var tCookievalue = {id: id, lastRunDate: lastRunDate}; //Since there are two values, we are passing an object.

    //Setting the actual cookie
    document.cookie = [tCookiename, JSON.stringify(tCookievalue)].join('=');

    window.location('<%= ResolveUrl("~/GUI/DataReviewNEW.aspx") %>')
}

function readCookie(n){
    var tC = document.cookie || '';
    tS = tC.split(n + '=').pop().split(';')[0];
    return JSON.parse(tS)
}

readCookie('$DataFileKey')

Addition

Yes, of course the values can be set seperately:

//Settings '$DataFileKey'
document.cookie = ['<%= this.CookieDataFileKey %>', id].join('=');

//Settings '$DataWhatever'
document.cookie = ['<%= this.CookieDateCompleteEnd %>', lastDateRun].join('=');

function readCookie(n){
    return (document.cookie || '').split(n + '=').pop().split(';')[0]
}

readCookie('$DataFileKey')

使用以下代码:

document.cookie = "$(<%= this.CookieDataFileKey %>) =" + id +'"';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM