2

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...

0

3 Answers 3

2

It's not possible. you can use cookie or local database to share data between html files.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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.

3 Comments

" The solution is theoretical " please comment back if this really works ? Curious to know if this works :)
The solution works, have seen this on pages. I have written "is theoretical" because I do not have my computer right now to give you a correct fiddle with working code. if both pages come from the same domain, you are allowed to access back and forth between them.
I'm sorry for being misleading, the window has the parent reference to the outer html, as in my test case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.