Page 1 of 1

iframes

Posted: Mon Mar 20, 2006 10:15 pm
by s.dot
I have two iframes housed on one page

when I click a link in the top iframe, i want it to change the source of the bottom iframe.

this is what I have

Code: Select all

<script type="text/javascript">
<!--
function showInfo(who){
	document.getElementById("infoBox").location.href = 'http://www.yahoo.com';
}
//-->
</script>
then in the iframe where the links will be clicked i have this code

Code: Select all

echo "<a href=\"javascript:void;\" onClick=\"javascript:parent.showInfo('{$array['username']}');\">".$array['username']."</a>";
I expect when that's clicked for the src of the lower iframe to be changed to yahoo.com (like the function states), but it's not happening.

What am I doing wrong :-S

Posted: Mon Mar 20, 2006 10:18 pm
by feyd
remove the javascript: ?

Posted: Mon Mar 20, 2006 10:25 pm
by s.dot
this is still a no-go

Code: Select all

echo "<a href=\"#\" onClick=\"parent.showInfo('{$array['username']}');\">{$array['username']}</a><br />";
I really suck at javascript. Should it be window.document.showInfo()?

Or in my function should it be something like, document.frames[1].location.href=''; =/

Posted: Mon Mar 20, 2006 10:29 pm
by s.dot
k, document.frames[] in the function seemed to work good.

Posted: Mon Mar 20, 2006 11:18 pm
by d3ad1ysp0rk
From what I've read, accessing things directly like that is a slight no no and your original code was more along the lines of what you should be doing.

Thing is, with getElementById, I don't believe you need the location part, since you're accessing it's properties directly.

Try something like this:

Code: Select all

document.getElementById("infoBox").src = 'http://www.yahoo.com';
No promises, but yeah ;)

Posted: Tue Mar 21, 2006 12:12 am
by s.dot
any reason why this won't work in firefox?

Code: Select all

<script type="text/css">
<!--
function showInfo(who){
	document.frames[1].location.href = 'chatinfo.php?u='+who;
}
//-->
</script>
on the same page i have this

Code: Select all

<a href="javascript:void;" onClick="showInfo('bob');">bob</a>
inside of a frame on the page i have this

Code: Select all

<a href="javascript:void;" onClick="parent.showInfo('bob');">bob</a>
Neither one of those work, but they both do in IE.

Posted: Tue Mar 21, 2006 12:23 am
by s.dot
The javascript console says

Error: document.frames has no properties
Source File: http://204.15.77.162/~smptest/chat.php?room=1
Line: 26

Posted: Tue Mar 21, 2006 12:46 am
by s.dot
k, i guess I talk myself through these sometimes :P

I tried this

Code: Select all

function showInfo(who){
   var uFrame = document.getElementById("infoBox");
   uFrame.src = 'whatever';
}
And that worked in both browsers.