Reputation: 245
I have 2 HTML files, and 1 JS file
index.html
index1.html
main.js
in main.js
i have a global object like as follows
var global={
a:''
}
from index.html
I assigned a=10;
<script>
global.a=10;
</script>
from index1.html
when I tried to access the value i am getting undefined
<script>
alert(global.a);
</script>
Is there any way That I can access that value with out Sessions/localstorage ?
Upvotes: 0
Views: 384
Reputation: 223
You could set it as a variable in the URL query string, and then read the query string for the value.
Something like:
index.html?variable=value
Another option would be to set a cookie with the variable key/value, and then read the cookie when the page loads.
document.cookie=variable + "=" + value;
Upvotes: 1