PDA

View Full Version : target iframe link using javascript



sassy_monix
12-10-2004, 02:13 AM
Hi! I have 3 iframes in one page...One of the iframes contains the menu and I want the other 2 iframes to change once the link in the menu is clicked. I tried using this code



<script language="javascript">
function loadTwo(iframe1URL, iframe2URL)
{
parent.FRAME1.location.href=iframe1URL
parent.FRAME2.location.href=iframe2URL
}
</script>


but it won't work if the link is coming from another iframe. Please help me. I've been stuck with this problem for hours and hours already! :(

ArcticFox
12-10-2004, 05:44 AM
I've several iFrames on my site:

http://arctic.ithium.net/

...that do all sorts of cross-linking tasks.

View-source to find your answer. :)

Brandoe85
12-10-2004, 06:03 AM
ArticFox..just encase you didnt know..when i go to your site it throws an error in my javascript console...though, i saw your site said under construction..so you probly allready know, but i was just pointing it out just encase :)

Kor
12-10-2004, 10:07 AM
You may:

1.- use a simple HTML action

<a href="page1.html" target="iframe">PAGE1</a>
<a href="page2.html" target="iframe">PAGE2</a>
...
<iframe name="iframe" src="page0.html"></iframe>

2.- or

top.frames['iframe'].location.href = 'page1.html';
top.frames['iframe'].location.href = 'page2.html';

3.- or

document.getElementById('iframe').setAttribute('src',''page1.html');
document.getElementById('iframe').setAttribute('src',''page2.html');

but use id for iframe
<iframe id="iframe" src="page0.html"></iframe>

hurrikane
01-19-2005, 10:20 PM
Is there a way to target all the links in an iFrame to a new window even if the page that is being loaded into the frame is an external source which can not be modified.

Example: I creat an iFrame with www.sony.com info in it. Can I have all the links open in a new window rather than refresh the iFrame?

Basscyst
01-19-2005, 10:58 PM
Is there a way to target all the links in an iFrame to a new window even if the page that is being loaded into the frame is an external source which can not be modified.

Example: I creat an iFrame with www.sony.com info in it. Can I have all the links open in a new window rather than refresh the iFrame?

Nope. Can't do it.

Basscyst

Ubunfu
07-11-2012, 03:23 PM
You may:

1.- use a simple HTML action

<a href="page1.html" target="iframe">PAGE1</a>
<a href="page2.html" target="iframe">PAGE2</a>
...
<iframe name="iframe" src="page0.html"></iframe>

2.- or

top.frames['iframe'].location.href = 'page1.html';
top.frames['iframe'].location.href = 'page2.html';

3.- or

document.getElementById('iframe').setAttribute('src',''page1.html');
document.getElementById('iframe').setAttribute('src',''page2.html');

but use id for iframe
<iframe id="iframe" src="page0.html"></iframe>

I know this is an extremely old thread, but this is exactly what I needed (thanks :D). Although, to save the next new guy like me some time, there's an extra tick mark you don't need before 'page1.html' and 'page2.html' in option 3.