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.
[02:41 am]
Oh_Man -- i used to play TF2 competitive in that clan, and also was PR manager (ie: i wrote all the website posts)
[02:41 am]
Oh_Man -- another fun fact iaguz actually joined the clan i was part of - Frenetic Array
[02:40 am]
Symmetry -- Human memory is a fragile, fallible thing
[02:39 am]
Oh_Man -- i realised all his shit was halluc and i wiped out his measly army of fake hallucs and he called GG - yeah thts wat actually happened damn false memory strikes again
[02:38 am]
Oh_Man -- i was zerg, the toss guy did a bunch of hallucinates, and i was like, welp, i guess i'm dead, but i have that mindset of never giving up, so attacked him anyway, then tht was wen
[02:38 am]
Oh_Man -- coz i was actually a zerg main, so wat ACTUALLY happened was a complete reverse of this
[02:37 am]
Oh_Man -- i found an old comment of mine i actually think the idra thing over-ride my own memory
[02:22 am]
Symmetry -- was it idra
[01:52 am]
NudeRaider -- Oh_Man
Oh_Man shouted: and i went on to win the tournament, and a pair of steelseries headphones. i even reember how i won the final match - hallucinated a fck-tonne of units and my opponent thought i had way more than he did and GGed
classic
[02:56 pm]
Oh_Man -- long story short - patience is a virtue!
Please log in to shout.


Members Online: Zycorax