Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript
Hi! Can you help me improve this code in that when "OK" is clicked, cookie is set but when "Cancel" is clicked, cookie is not set
 

function rC(nam) 
{
var tC = document.cookie.split('; '); 
for (var i = tC.length - 1; i >= 0; i--) 
{
  var x = tC[i].split('=');
  if (nam == x[0]) 
    return unescape(x[1]);
} 
return '~';
} 
 
function wC(nam,val) 
{
document.cookie = nam + '=' + escape(val);
} 
 
function lC(nam,pg) 
{
var val = rC(nam); 
if (val.indexOf('~'+pg+'~') != -1) 
  return false; 
 
val += pg + '~'; 
wC(nam,val); 
return true;
} 
 
function firstTime(cN) 
{
return lC('pWrD4jBo',cN);
} 
 
function thisPage() 
{
var page = location.href.substring(location.href.lastIndexOf('\/')+1); 
pos = page.indexOf('.');
if (pos > -1) 
{
page = page.substr(0,pos);
} 
return page;
}
 
// example code to call it - you may modify this as required
function start() {
   if (firstTime(thisPage())) {
      // this code only runs for first visit
      var answer = confirm ("Please click on OK to continue loading my page, or CANCEL to be directed to the Yahoo site.")
if (!answer)
window.history.back();
   }
   // other code to run every time once page is loaded goes here
}
onload = start;
Posted 1-May-13 12:46pm
Edited 7-May-13 7:21am
v4

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

// example code to call it - you may modify this as required
function start() {
   if (firstTime(thisPage())){
      // this code only runs for first visit
      var answer = confirm ("Please click on OK to continue loading my page, or CANCEL to be directed to the Yahoo site.");
     if(answer)
     {
       lC(nam,pg);// with whatever nam and pg is
     }
     else
     {
       window.history.back();
     }
   }
   // other code to run every time once page is loaded goes here
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 7 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100