View Full Version : calling on variables in iframes
ASAAKI
10-02-2002, 11:00 PM
i have a page with an iframe,named 'gamescreen'. why doesn't top.frames["gamescreen"] exist?? :mad: how can i refer to variables in the iframe page? :confused: :mad:
Quiet Storm
10-03-2002, 02:39 AM
What kind of variables were you looking to have?
glenngv
10-03-2002, 07:00 AM
try:
window.gamescreen.theVariableName
beetle
10-03-2002, 07:06 AM
or window.gamescreen.window.variableName
ASAAKI
10-03-2002, 09:52 AM
arrrrggghhhhh!:mad: they don't work! not them and not a whole heap of other combinations that i've been racking my brains to come up with.
glenngv
10-03-2002, 10:07 AM
can you post the code of the page where the iframe is?
maybe you are accessing the iframe before it is even loaded.
ASAAKI
10-03-2002, 10:21 AM
well there's hardly anything coz i just started it.
<head>
<script src="bombgame.js"></script>
</head>
<body>
<center>
<iframe src="iframe.htm" name="gamescreen" style="width:85%; height:90%; border:2px solid; border-color:gray" frameborder="0" scrolling="no"></iframe>
<BR>
<input type="button" value="Start!" onclick="this.blur()">
</center>
</body>
the code that was supposed to start like a nice little, well-behaved code on the bombgame.js page was this:
top.totalbombs=10
top.bps=2
top.bombno=0
//the next two lines are the problem
gamescreen=top.frames["gamescreen"]
gamescreen.bombid=[]
actually the whole game was showing signs of working pretty well, on a single page, before i changed my mind and wanted it in an iframe within a page, and started all over again.
glenngv
10-03-2002, 11:00 AM
i was correct! you accessed the iframe before it was even loaded.
<head>
<script src="bombgame.js"></script>
</head>
<body>
<center>
<iframe src="iframe.htm" name="gamescreen" style="width:85%; height:90%; border:2px solid; border-color:gray" frameborder="0" scrolling="no"></iframe>
<BR>
<input type="button" value="Start!" onclick="this.blur()">
</center>
</body>
once the bombgame.js is loaded, it will execute the code inside it but the iframe hasn't been loaded yet.
the solution is, put the codes in a function and call it onload
ASAAKI
10-03-2002, 12:45 PM
zangk u!! zat iz currrect! merci, merci :D
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.