I have been looking for ages trying to find a way to access a variable in another .html file. For example: File 1 (HTML)
<!--some code--> <script> var x; //this should equal the variable in the other file. </script>
File 2 (HTML)
<!--some code--> <script> var y = 0; </script>
How could I do it? (I can move file 2's code into a separate .js file.
You'll have better luck storing the variable in localStorage.
Set the key in one page
localStorage.setItem('key', value);
Retrieve the value from another
localStorage.getItem('key')
The other way is to use cookies.
2.1m questions
2.1m answers
60 comments
56.9k users