Ask coding questions

← Back to all posts
API for javscript
MikeJMS8910 (234)

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.

xxpertHacker (931)

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

MikeJMS8910 (234)

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

xxpertHacker (931)

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

tussiez (1677)

localStorage works across the entire domain. This should work.
E.g you do localStorage.setItem('someThing','xyz'); on

someThing will still be xyz on

MikeJMS8910 (234)

@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?

tussiez (1677)

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

19wintersp (1143)

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.

Coder100 (18930)

did you just forget that's what localStorage solves

MikeJMS8910 (234)

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