+ 1
Is it possible to make a JavaScript variable accessible across all pages?
Make a JavaScript variable global(like to be accessible across all pages)
5 Answers
+ 2
Use Es6 export :
". /components/js/variables.js"
export const name = "hello";
".components/js/someOtherFile.js"
import { name} from "components/js/someOtherFile.js"
+ 1
Yes, it is possible. For example as with GET over URL.
+ 1
I don't think that's possible.
Use localstorage api to store value of variable. It'll be accessible on all pages of your domain.
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
Note: localstorage doesn't work in this app's playground.
+ 1
Declare it as a property in the window object
window.someVar = "some value"