NationStates Jolt Archive


html/javascript help needed

Pure Metal
24-07-2006, 18:15
right... this isn't homework help as its not homework, and i'd love to ask this on a web-development forum but i don't know any and as a noob i would expect not necessarily getting an answer. so.... i have a problem with some code.

what i want to happen is for a page to load into an iframe and then for an onload handler in that page to automatically load a different file into another iframe on the main page. got it?
i even did a picture to help explain and be clear:

http://www.hlj.me.uk/help.jpg


but i can't work out how to do it :(




tried a few things from simple

<body onLoad="window.load('page.htm', target="topframe");">

to

<a href="page.htm" id="opentitle()"
target="topframe" onload="window.load(this);
return false">if you can see this, please click here</a>

but nothing works and i feel like i'm stabbing about in the dark.
anyone got any clues? maybe my syntax is wrong or maybe i'm going about this all the wrong way... i'd really, really appreciate any insights or help as if i can't get this sorted its kinda back to square 1 on the site :-S
Kazus
24-07-2006, 18:23
Try the first one, only instead of window.load try


frames['iframeName'].location.href="whatever";
Lazy Otakus
24-07-2006, 19:03
This could work, but it will take one or two second for the page to load (dunno why, don't know much about Javascript):

<script language="JavaScript" type="text/JavaScript">
<!--
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
//-->
</script>
<body MM_goToURL('parent','wheredoyouwanttogotoday.htm');return document.MM_returnValue" >
Pure Metal
24-07-2006, 19:53
thanks for the help guys but they don't work :(
not sure why - they both look like they should!


am still searching for something to no avail...
Iztatepopotla
24-07-2006, 20:35
thanks for the help guys but they don't work :(
not sure why - they both look like they should!


am still searching for something to no avail...
I think you're approaching the problem from the wrong angle. What do you want to do and why do you need iframes? Perhaps there's another way to do it through divs and dhtml.

Have you tried 'target="_parent"' ?
Demented Hamsters
24-07-2006, 20:42
thanks for the help guys but they don't work :(
not sure why - they both look like they should!


am still searching for something to no avail...
Do what I always do:
troll through the internet til you find a site that's doing what you want, then check it's source code.

Worked for me. Got me through a webpage paper without me learning a damn thing.
Safalra
24-07-2006, 20:45
what i want to happen is for a page to load into an iframe and then for an onload handler in that page to automatically load a different file into another iframe on the main page. got it?
As far as I know this can't be done due to Javascript data tainting meaning iframes can't detect their environment. It doesn't matter though as you can take a different approach - replace the iframe with a div with the appropriate width and height and overflow:auto set (this will make it behave like an iframe). You can then either copy the code that would be in the iframe into the div by hand, or use your favourite server-side technology to do the same. The code can now access its external environment through the normal route.
Si Takena
24-07-2006, 20:46
That's what I do too ^.^
Lerkistan
25-07-2006, 01:43
Could you made this work now? What was wrong with this solution ->

frames['iframeName'].location.href="whatever";

is that if you're in an iframe and want to access another iframe, you'll have to "route" over the parent first, because the second iframe is not part of the first iframe, but part of the parent frame. Uh... anyway... it's late, don't expect me to be articulate now... just do this:

parent.frames['iframeName'].location.href="whatever";

I tested it with the following code:

main window:

<html>
<body>
<iframe src="a.html"></iframe>
<iframe name="other" src=""></iframe>
</body>
</html>

a.html

<html>
<body onload="parent.frames['other'].location.href='b.html'">
test...
</body>
</html>

b.html:

<html>
<body>
another test...
</body>
</html>


This seemed to do what you wanted.

P.S: First post, no gun smiley. :)
Posi
25-07-2006, 02:11
P.S: First post, no gun smiley. :)
FREAK!
Lerkistan
25-07-2006, 10:54
FREAK!

After lurking this forum for a few weeks, I really looked forward to bragging about not using gun smileys. This is the first time I had actually something to contribute, though.
Pure Metal
25-07-2006, 12:02
After lurking this forum for a few weeks, I really looked forward to bragging about not using gun smileys. This is the first time I had actually something to contribute, though.
thank you ever so much... guess what? it works! :D :D

now i have other problems but meh, thats always the case, heh :p



have some lovely cake (http://img135.imageshack.us/img135/9366/cakewq4.jpg) and a hug *hugs* :) (not sure if your name really is kenny, or kerry, or whatever that cake says... but that's the tastiest looking cake i could find a picture of, damnit! :p)

ps: go you and the gun smilies! :P
Lerkistan
25-07-2006, 14:54
Looks tasty :)

Hmm, web design is just like programming. It's the most fun if you can get something done, but you spend 80% of the time wondering why on earth that stuff won't work...
Kazus
25-07-2006, 15:17
I didnt think you needed the parent in front. I thought the frames array was global.