I'm trying to make a sort of map with data that overlays based on what a user selects. Currently, I just have the image on the same page shrunken, but it's rather hard to read. I was thinking I could have the entire image in an iframe and just have the user be able to scroll around the map, but Im not sure if I can use the javascript between the two pages. Would it be possible or do I have to figure out another way to get a full size image?
Asked
Active
Viewed 151 times
2 Answers
2
If the two pages are on the same domain, then you will be able to transfer information between them. If not, there are still ways to transfer JSON data between domains (using JSONP) but it will be much harder.

bmarti44
- 1,247
- 2
- 14
- 22
-
And how would I reference that? – NatFan9 Nov 17 '12 at 21:00
-
Some info on using postMessage (check the compatibility of this method) http://benalman.com/code/projects/jquery-postmessage/examples/iframe/ – bmarti44 Nov 17 '12 at 21:11
-
Simpler way to communicate between the 2 windows http://stackoverflow.com/questions/4601325/trigger-events-in-iframes-parent-window – bmarti44 Nov 17 '12 at 21:12
-
Info on Same Origin Policy and why you can't (easily) do cross domain data http://stackoverflow.com/questions/2538215/cross-domain-scripting-issues-jsonp – bmarti44 Nov 17 '12 at 21:15
-
I read both, and I still dont really get how i would reference an object. They are on the same domain, but I take it it's still not as easy as something like document.getElementById("button").src – NatFan9 Nov 17 '12 at 22:06
-
So I understand how to reference an object from the iframe to outside the iframe, but how would I have something outside, reference something inside or am I thinking this out to much? – NatFan9 Nov 17 '12 at 22:16
-
window.frames['nameofiframe']; will do from parent -> child. Referenced here -> http://stackoverflow.com/questions/10748449/access-and-change-parent-page-from-iframe-with-jquery – bmarti44 Nov 17 '12 at 22:29
-
I would highly recommend doing this with a javascript framework (I'm looking at you jQuery) – bmarti44 Nov 17 '12 at 22:31
-
So would this be the proper way to do it? window.frames['map'].document.getElementById("button").src – NatFan9 Nov 17 '12 at 22:42
-
Putting this in my JS console -> console.log(window.frames['map'].document.getElementById("img").src); shows -> http://i805.photobucket.com/albums/yy331/NatFan/basemap.png Which is correct, i would just double check you're ID – bmarti44 Nov 17 '12 at 22:46
-
Ah. Fixed the little problem I had. Thanks so much. – NatFan9 Nov 17 '12 at 22:52
0
Yes you can. In fact, you can call functions in one javascript file that only exist in another (provided you add them in the right order).
If you aren't in the same domain, you can use JSONP to freely send cross-domain requests back and forth.

Community
- 1
- 1

Sean Lindo
- 1,387
- 16
- 33