Forum Moderators: open

Message Too Old, No Replies

iframes

How to keep the new page inside the iframe, like regular frames

         

1nfinite

4:18 am on May 18, 2003 (gmt 0)

10+ Year Member



I have a website, that uses iframes, and i was wondering, if and how it is possible to load new pages into the iframe. Like i have the news part in an iframe, and when you click a new link from the nav the entire page loads it, all i want is it to load inside the iframe, but i dont want to do it with regular frames, anyone know?

dmorison

4:32 am on May 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do it in JavaScript;

Give your IFRAME an ID:

<iframe id='newsframe' width='300' height='400' src='about:blank'>
</iframe>

And then an example link in your nav section would be:

<a href='javascript:document.all.newsframe.src="news.html";'>News</a>

Hope this helps!

dmorison

4:38 am on May 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, that was the off the top of my head answer;

You actually just need to give the IFRAME a "name" attribute, and then put the name you give it into the target attribute of a link...

<iframe name='newsframe' width='300' height='400' src='about:blank'>
</iframe>

so this time an example link in your nav section would be:

<a href='news.html' target='newsframe'>News</a>

That's better :)

1nfinite

4:40 am on May 18, 2003 (gmt 0)

10+ Year Member



damn it didnt work... this is what i had

<iframe id='newsframe' width=100% name="iframe" height=100% frameborder="0" src="iframe.html"></iframe>

and for the link..the same as you

<a href='javascript:document.all.newsframe.src="info.html";'>News</a>

But when you click the link, it just opens the whole window and says "info.html"

1nfinite

4:42 am on May 18, 2003 (gmt 0)

10+ Year Member



Oh, ok, i didnt read before i posted the last one, i already had the iframe named, just didnt know how to put the link,

Thanks alot man, ill try it

1nfinite

4:43 am on May 18, 2003 (gmt 0)

10+ Year Member



wow thanks alot, worked perfect :D

dmorison

4:53 am on May 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Interesting. Using target is the correct way to do it, but I think we found a bug in IE :)

Works:


<script type='text/javascript'>

function Go()
{
document.all.foo.src="foo.html";
}

</script>

<iframe id='foo' width='200' height='200'></iframe>

<a href='javascript:Go();'>Test</a>

Doesn't work: (does what you said above - very odd)


<iframe id='foo' width='200' height='200'></iframe>

<a href='javascript:document.all.foo.src="foo.html";'>Test</a>

Anybody?

figment88

5:01 am on May 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I believe it would work better if you used location instead of src.