Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6129121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:42:19+00:00 2026-05-23T16:42:19+00:00

I wanted to store variables per tab scope. This same question was raised already

  • 0

I wanted to store variables per tab scope. This same question was raised already and the suggestion was to use localStorage. But how to use localStorage to save associative arrays?

For example: A user is logging in a site. I want to create a variable to refer to that user. This way the user will open many tabs and he will log in to many sites. So I need to maintain the domain name and the user reference in localStorage, so if I use the username as a unique field then I can maintain an association with reference to the username, and finally I will need to store this information in the database.

So, how to maintain a data structure in a Google Chrome extension? The above is just an example, but it could be any case where we need the same variable name in various tabs with different values.

The documentation states to use JSON format. But still I want the users’ suggestion on this.

So any kind of response will he helpful, like answers, suggestions, references and comments.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:42:20+00:00Added an answer on May 23, 2026 at 4:42 pm

    It is not very clear from your question what do you mean by “tab scope”.

    If you really need the tab scope, that is store values for this specific tab even when user navigates to a new site, then you can take tabid as a key (only tab id is not persistent between browser restarts).

    If you actually mean “domain scope” – then it comes “for free” with content scripts. If you use localStorage inside a content script it would store the value only for this domain. You only need to make sure your keys don’t collide with potential site’s keys as the site might use the same localStorage.

    If you are just asking how to create a data structure that would have domain names as keys, then it could be something like this:

    var data = {};
    data["google.com"] = {
        username: "user1",
        password: "pass1"
    };
    data["yahoo.com"] = {
        username: "user2",
        password: "pass2"
    };
    
    //store it
    localStorage["data"] = JSON.stringify(data);
    
    //load
    data = JSON.parse(localStorage["data"]);
    
    //read google username
    console.log(data["google.com"].username);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry if this is a total noob question, but I wanted to try to
I posted a question about this earlier, but I have more information now and
This question is related to hooking with Mobile Substrate, but as long as you
I wanted to store 10 in 4th position of array of 5 positions. How
i have several classes with members called 'Id'. Originally i wanted to store these
I have been using anonymous namespaces to store local data and functions and wanted
Wanted to know if someone had a suggestion on code or maybe there's a
I wanted to show the users Name Address (see www.ipchicken.com ), but the only
I wanted to generate one fix view using interface builder, but the size of
If I have a list of global variables like this... int a; char b;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.