Staredit Network > Forums > Technology & Computers > Topic: Help me out, I'm Javascripture Illiterate
Help me out, I'm Javascripture Illiterate
Nov 21 2009, 10:20 am
By: Syphon  

Nov 21 2009, 10:20 am Syphon Post #1



I have a document set up like this.

Code
┌root

├──iframe
│  │
│  └──scripta

└──scriptb


Inside scripta, x is set to some value.

How do I access this value within scriptb, as soon as it's available? Preferably, give your example as printing it within root. I tried just setting a do nothing while loop that terminated when it was set, but that makes the browser hang. (For longer than it should?)



None.

Nov 21 2009, 1:37 pm Forsaken Archer Post #2



Hmm... seems like you just need a different way of thinking this out. What happens when x is set? Can you just provide the real problem?



None.

Nov 21 2009, 2:47 pm Falkoner Post #3



I've never heard of a way of accessing variables from a page within an iframe, I think browsers simply load it as a completely different page, and if you could modify it you'd be able to modify other pages in the browser.



None.

Nov 21 2009, 5:35 pm Forsaken Archer Post #4



Quote
I tried just setting a do nothing while loop that terminated when it was set, but that makes the browser hang.
I assume here that he has absolutely no problem accessing it, just his method sucks and he's hoping for something that doesn't hang. I mean, if it wasn't even a possibility to share javascript values between frames, you could write the variable to the iframe html and then access that to share it with the parent javascript.



None.

Nov 22 2009, 12:40 am Syphon Post #5



This is the real problem, IP. :P

It's literally all I'm doing - I'm trying to get better at JS.

I can access it perfectly fine once I cause an event and the page has finished loading, the problem is I want determine exactly when it's set, and then output it in the parent document.

Code
<iframe src='page2' id='frame'></iframe>

<script>
document.write(window.frame.x);
</script>


Code
<script>
var x;
x = 'test';
</script>


Obviously I shouldn't be using document.write, but innerHTML(whatever) = window.frame.x, but whatever. I just need to know how to check when window.frame.x is set.

Post has been edited 1 time(s), last time on Nov 22 2009, 12:48 am by Syphon.



None.

Nov 22 2009, 4:36 am O)FaRTy1billion[MM] Post #6

👻 👾 👽 💪

That code works (tested in Chrome, FireFox 3.5, and IE8), you just need to wait for the 2nd page to load.
Code
<iframe src='page2.htm' id='frame'></iframe><br />
<input type='button' value='Get x' onclick='alert(window.frame.x);' />




TinyMap2 - Latest in map compression! ( 7/09/14 - New build! )
EUD Action Enabler - Lightweight EUD/EPD support! (ChaosLauncher/MPQDraft support!)
EUDDB - topic - Help out by adding your EUDs! Or Submit reference files in the References tab!
MapSketch - New image->map generator!
EUDTrig - topic - Quickly and easily convert offsets to EUDs! (extended players supported)
SC2 Map Texture Mask Importer/Exporter - Edit texture placement in an image editor!
\:farty\: This page has been viewed [img]http://farty1billion.dyndns.org/Clicky.php?img.gif[/img] times!

Nov 22 2009, 8:10 am Forsaken Archer Post #7



Why not, then, just call a function when x is changed, passing it to a parent function? Obviously x is set because the function is called.



None.

Nov 22 2009, 12:58 pm Syphon Post #8



I ended up just using setTimeout() and setInterval()... Works well enough but I guess server lag will break a bit if I set it to check too often.



None.

Options
  Back to forum
Please log in to reply to this topic or to report it.
Members in this topic: None.
[07:32 pm]
Zoan -- I got $2000 bonus. I would like 2000 minerals, please
[04:15 am]
DarkenedFantasies -- you eat lots of beans
[03:46 am]
IskatuMesk -- how do i get gas
[11:43 pm]
Moose -- you don't
[10:06 pm]
Zoan -- how do i get minerals
[2026-4-14. : 11:45 pm]
ClansAreForGays -- Anyone wanna played Skewed StarCraft?
[2026-4-14. : 12:07 am]
Vrael -- NudeRaider
NudeRaider shouted: Vrael ranting still is though
you're a gentleman and a scholar, thank you
[2026-4-13. : 10:07 pm]
NudeRaider -- ya why phone people when you can just write letters
[2026-4-13. : 9:37 pm]
IskatuMesk -- I have never and will never own a phone
[2026-4-13. : 9:15 pm]
NudeRaider -- Vrael ranting still is though
Please log in to shout.


Members Online: Prankenstein, Zincoshine