0

Basically I have a function that reads cookies. getCookie('message').

When getCookie('message') value changes I want to display an alert with the new value.

I think the function can be treated as a variable. Thus the question's title if not please let me know so I correct it. How can I listen for a change in the value the function returns?

1
  • you want to display whenever the page refreshed or you should show alert if it is a new request also. Commented Nov 29, 2012 at 6:53

2 Answers 2

6

basic polling example

var message = getCookie('message');
setInterval(function(){
    var m = getCookie('message');
    if(m != message) {
        message = m;
        alert(message);
    }
}, 1000);
Sign up to request clarification or add additional context in comments.

Comments

-1

Ok. So you want to read the value of cookie. That is somewhat easy like this -

To read out a cookie, call this function and pass the name of the cookie. Put the name in a variable. First check if this variable has a value (if the cookie does not exist the variable becomes null, which might upset the rest of your function), then do whatever is necessary.

var x = readCookie('ppkcookie1')
  if (x) 
   {
    alert("this is a change"+x)
   }

Cookie read.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.