S
S
Stalin's partisan2017-12-16 11:17:55
JavaScript
Stalin's partisan, 2017-12-16 11:17:55

Why doesn't the code take cookies?

Tell me what is wrong or what is missing, there is a system on the site - you put a tick in front of the ad and it is entered in cookies, and then you open a notepad in a new window and there is the ad in front of which there was a checkmark.
But after opening the ad window, it does not load there, and after refreshing the page, the label that there is an entry in the notepad disappears.

//// блокнот

function window_notepage()
{
var height_w=screen.height-250;
var left = (screen.width/2)-(650/2);
var top = (screen.height/2)-(height_w/2);
window.open('notepage.html','note_board','width=650,height='+height_w+',top='+top+',left='+left+',toolbar=0, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no');
}
function add2note()
{
  function str_replace(search, replace, subject) { return subject.split(search).join(replace);}
var button = document.getElementById('addnotepage');
var Link2Note = document.getElementById('Link2Note');
var count_note_message = 0;
var id = 731000;
var fid = 2;
value = fid+"i"+id+"s";
var cookies = getCookie("BoardNote");
if (cookies == undefined) cookies = "";

//проверяем, есть ли это объявление в куки блокнота?
if (cookies.search(value)!= -1) 
  {  	
    //если есть, удаляем
    value = str_replace(value,"",cookies);
    button.style.backgroundImage = 'url(img/check_icon_off.png)';
    button.style.borderColor = '#aaaaaa';
    button.style.backgroundColor = '#eeeeee';
    button.title='Добавить в блокнот';
    count_note_message = value.split("s").length - 1;
    if (count_note_message>0) Link2Note.innerHTML = "<u>Блокнот ("+count_note_message+")</u>";
    if (count_note_message<=0) Link2Note.innerHTML = "<u>Блокнот</u>";
    
  }
else
  {
    //если нет, добавляем
    value = cookies+value;
    button.style.backgroundImage = 'url(img/check_icon.png)';
    button.style.borderColor = '#88ee88';
    button.style.backgroundColor = '#eeffee';
    button.title='Удалить из блокнота?';
    count_note_message = value.split("s").length - 1;
    if (count_note_message>0) Link2Note.innerHTML = "<u>Блокнот ("+count_note_message+")</u>";
  }
setCookie("BoardNote", value, { expires: 3600*24*30, path: "/", domain: ".a0174767.xsph.ru"  });
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
My joy, 2017-12-16
@t-alexashka

I think you screwed something up with the domain. In any case, I advise you this crumb:
Kizzy which weighs 2kb, and greatly simplifies the work with cookies, replacing storage, if possible, in localStorage.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question