iframes

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

iframes

Post 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
Last edited by s.dot on Tue Mar 21, 2006 12:13 am, edited 2 times in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

remove the javascript: ?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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=''; =/
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

k, document.frames[] in the function seemed to work good.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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 ;)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply