Skip to content
← Back to Community
API for javscript
Profile icon
Michael8910

So I am using javascript's local storage API but I don't think that I will be able to use this. I have 2 different HTML files and in one of them, you can add a save, and in another, you can open a save. Since they are on different files thought they do not work so how can I make an API for both of these files.

Voters
Profile icon
ThanaPTz
Profile icon
EpicCoderGuy1
Profile icon
Michael8910
Comments
hotnewtop
Profile icon
xxpertHacker

Please don't say that you're saving whole files to localStorage?

Profile icon
Michael8910

@xxpertHacker no I am only using it to save a URL

Profile icon
xxpertHacker

@MikeJMS8910 Oh, okay, don't mind me then.

Profile icon
tussiez

localStorage works across the entire domain. This should work.
E.g you do localStorage.setItem('someThing','xyz'); on test.tussiez.repl.co/index.html

someThing will still be xyz on test.tussiez.repl.co/page2.html

Profile icon
Michael8910

@tussiez wait so this means that if you were to use a key in an entirely different repl or website where they also use local storage you would still get that data?

Profile icon
tussiez

@MikeJMS8910 Luckily, no
It's based off of the subdomain:
blog.repl.it != repl.it

Profile icon
Michael8910

@tussiez ok cool

Profile icon
tussiez

@MikeJMS8910 Did you figure it out?

Profile icon
Michael8910

@tussiez yes thank you

Profile icon
tussiez

@MikeJMS8910 Awesome!

Profile icon
19wintersp

LocalStorage data is stored by the browser on the client. Your site, no matter what page it is on, will be able to access the same LocalStorage database from each page.

Profile icon
Coder100

did you just forget that's what localStorage solves

Profile icon
Michael8910

@Coder100 doesn't local storage save data to a key

Profile icon
Coder100