+ 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)

7th Oct 2020, 10:34 AM
Ndemafia Wilsmith
Ndemafia Wilsmith - avatar
5 Respostas
+ 2
Use Es6 export : ". /components/js/variables.js" export const name = "hello"; ".components/js/someOtherFile.js" import { name} from "components/js/someOtherFile.js"
7th Oct 2020, 8:01 PM
Tekashi69{Oliseh}
Tekashi69{Oliseh} - avatar
+ 1
Yes, it is possible. For example as with GET over URL.
7th Oct 2020, 10:56 AM
JaScript
JaScript - avatar
+ 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.
7th Oct 2020, 10:58 AM
🇮🇳Omkar🕉
🇮🇳Omkar🕉 - avatar
+ 1
Declare it as a property in the window object window.someVar = "some value"
7th Oct 2020, 1:31 PM
CHMD
CHMD - avatar