ThemeForest

How to update a jquery variable globally in HTML

438 posts
  • Has been a member for 2-3 years
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a File in an Envato Bundle
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • India
SaurabhSharma says

For example, I have two copies of a page; both of which contain same jquery code. Something like:

$(document).ready(function () {
    var flag = 0;
    $('#anchor').click(function () {
        flag = 1;
    });
})

When I am on Page1 and clicked #anchor, the flag value changed to 1. Now if I return to Page2, I need the flag value to get modified, depending upon the action performed on Page 1; and vice versa. i.e. Modifying a variable on one page should update itself globally for all pages. How can this be done?

Any help is most appreciated. Thanks in advance

Posted 2 years ago Permalink
2278 posts
  • Has been a member for 2-3 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Europe
  • Referred between 50 and 99 users
CreativeMilk says

Use a cookie(use and not eat ;))

Posted 2 years ago Permalink
316 posts
  • Has been a member for 2-3 years
  • Won a Competition
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • Indonesia
  • Referred between 1 and 9 users
webinpixels says
Use a cookie(use and not eat ;))

+1 :D

Posted 2 years ago Permalink
438 posts
  • Has been a member for 2-3 years
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a File in an Envato Bundle
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • India
SaurabhSharma says
Use a cookie(use and not eat ;))

Thanks Mark. I will try with that. :)

Posted 2 years ago Permalink
2523 posts
  • Has been a member for 3-4 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Tutorial to a Tuts+ Site
  • Attended a Community Meetup
  • Interviewed on the Envato Notes blog
  • Envato Staff
  • Forum Moderator
  • Author had a Free File of the Month
  • Exclusive Author
  • Blog Editor
  • Sold between 10 000 and 50 000 dollars
  • Bought between 50 and 99 items
  • United States
  • Referred between 10 and 49 users
JeffreyWay says

Or – if it isn’t sensitive data, you can pass it through the query string.

But yeah – setting a cookie is probably the easiest method.

Posted 2 years ago Permalink
JeffreyWay is an Envato staff member
438 posts
  • Has been a member for 2-3 years
  • Contributed a Tutorial to a Tuts+ Site
  • Author had a File in an Envato Bundle
  • Exclusive Author
  • Sold between 100 000 and 250 000 dollars
  • Elite Author
  • India
SaurabhSharma says
Or – if it isn’t sensitive data, you can pass it through the query string. But yeah – setting a cookie is probably the easiest method.

Thanks Jeff. I had this done successfully with cookies and jquery cookie plugin. :)

Posted 2 years ago Permalink
by
by
by
by
by