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 8142647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:53:03+00:00 2026-06-06T12:53:03+00:00

localStorage is per domain/sub-domain, but I need to store and retrieve values per page.

  • 0

localStorage is per domain/sub-domain, but I need to store and retrieve values per page.

Does anyone have an expression that removes the domain, bookmarks and query-string from the location? I can then use encodeURIComponent and prepend each localStorage-key with this value.

In which case, I also need the ‘reverse’ to this expression in order to retrieve values just for the current page. EDITED I don’t think I need a ‘reverse’ function – it would be the same expression.

If I have the two expression above, would you use this (stripped) location as a single key-entry, and stringify all the values I need for the page within it? This might be preferable as I can just check the location once to discover if it has any corrresponding localStorage.

  • 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-06-06T12:53:05+00:00Added an answer on June 6, 2026 at 12:53 pm

    I have a function that generates a key for me, based on the page name (gotten from window.location) and appended with what the key would have been, then I store the data in localstorage.

    function findPageName() {
        var path = window.location.pathname,
            s = path.split('/'),
            l = s.length,
            k = path.length,
            aux = 0;
    
        if (s[l - 1]) {
            return s[l - 1];
        } else if (l) { // l will always be a min of 2 (try '/'.split('/') )
            return s[l - 2];
        } else if (k == 0) {
            return '/'; //you likely want to replace this with another value
        } else {
            return s[1];
        }
    }
    
    function getKey(key) {
        return getPageName() + key;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used localStorage[key] and key being different strings to store my values while
I understand that HTML5 localStorage is a key:value store but I am wondering if
Is the HTML5 localStorage object isolated per page/domain? I am wondering because of how
I am learning about localStorage, and I understand that the limit is 5MB per
Since localStorage (currently) only supports strings as values, and in order to do that
In localstorage I have key ' results ' with this values : [{id:item-1,href:google.com,icon:google.com}, {id:item-2,href:youtube.com,icon:youtube.com},
I have a variable in my function that is static, but I would like
My store uses localStorage to store the cart. I've used this line to retrieve
I'd like to store a JavaScript object in HTML5 localStorage , but my object
I am using localStorage in a project, and it will need to store lots

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.