Reputation: 31
Especially I must indicate that I just have been started to developing javascript applications. my problem is that; I have an html page what includes my map. for example(a.html). Also i have javascript variable inside in this page it is (var map) My real problem is that i have another html page (b.html) and it includes an iframe which includes a.html. But i need to access my variable (var map) from b.html. How can I achieve it? is it possible? if it is not how can I solve this problem?
thanx...
Upvotes: 2
Views: 1031
Reputation: 389
You could create an empty variable in b.html
var mapCollector;
then after you load a.html
in the iframe
write your map to that back
document.parent.mapCollector = map;
or you could iterate through the iframes
in b.html
and grab the data that way.
The solution is theoretical as I do not have my environment right now.
Limitation is: both htmls have to come from the same domain.
EDIT :
The correct reference is:
window.parent.mapCollector = map;
Also look on my test case for a working solution.
Upvotes: 0
Reputation: 1811
If your browser supports HTML5 , you could use localStorage.
localStorage.setItem('my_key','my_value');
var n = localStorage('my_key');
The other alternative would be to use cookies.
So you should check first :
function supports_html5_storage() {
try {
return 'localStorage' in window && window['localStorage'] !== null;
} catch (e) {
return false;
}
}
More reading: http://diveintohtml5.info/storage.html
Upvotes: 0
Reputation: 4347
It's not possible. you can use cookie or local database to share data between html files.
Upvotes: 2