iframe help

PacersForever

New Member
Messages
21
Reaction score
0
Points
0
Is it possible to have buttons that change the iframe on your site ? Diagram below.


81780223vy3.jpg
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Yes.






Obviously I'll give some more info than just "Yes.", but that's all you asked for :p
It's actually quite easy, a normal <a> tag looks like this:
HTML:
<a href="http://forums.x10hosting.com/programming-help/url">
But there's a parameter "target" too:
HTML:
<a href="http://forums.x10hosting.com/programming-help/url" target="name">
This would open the link in the frame (iframe / frameset) named "name".
eg.
HTML:
<a href="http://www.google.com" target="frame">Google in frame.</a>
<iframe name="frame" />
 
Last edited:

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
that's a typo in the example by marshian. Add a 'p' into the link so it reads:
HTML:
<a href="http://www.google.com" target="frame">Google in frame.</a>
<iframe name="frame" />
 

scopey

New Member
Messages
62
Reaction score
0
Points
0
Or you could JS it.

HTML:
<button onclick="document.getElementById('frame').src = 'http://www.google.com';">Google.com</button>
<iframe id='frame' />
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
Or you could JS it.

HTML:
<button onclick="document.getElementById('frame').src = 'http://www.google.com';">Google.com</button>
<iframe id='frame' />
JS is good for this. However, make sure you use the following to ensure that it will work for more people:
HTML:
<script type='text/javascript>
   document.write ("<button onclick=\"document.getElementById('frame').src = 'http://www.google.com';\">Google.com</button>");
</script>
<noscript>
   <a href="http://www.google.com" target="frame">Google in frame.</a>
</noscript>

<iframe name='frame' id='frame'>
 

PacersForever

New Member
Messages
21
Reaction score
0
Points
0
Ok I have this now

PHP:
<a href="http://www.nba.com" target="frame">NBA</a>
</noscript>

<a href="http://www.google.com" target="frame">Google in frame.</a>
</noscript>

</p>
<script type='text/javascript>
   document.write ("<button onclick=\"document.getElementById('frame').src = 'http://www.google.com';\">Google.com</button>");
</script>
<noscript>
   <a href="http://www.google.com" target="frame">Google in frame.</a>
</noscript>

<iframe name='frame' id='frame'>


Is there a way to make the links buttons and for it to automatically open in one of the links ?
 
Last edited:

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
Is there a way to make the links buttons and for it to automatically open in one of the links ?
I'm not quite sure what you mean there...?
If you use the following code, it will make all your links buttons, and pressing a button will change the frame, depending on which button was pressed.
HTML:
<p>
<script type='text/javascript'>
  document.write ("<button onclick=\"document.getElementById('frame').src = 'http://www.google.com';\">Google</button>");  
  document.write ("<button onclick=\"document.getElementById('frame').src = 'http://www.nba.com';\">NBA</button>");
  </script>
<noscript>
  <a href="http://www.google.com" target="frame">Google</a> <a href="http://www.nba.com" target="frame">NBA</a>
<button onclick="document.getElementById('frame').src = 'http://www.google.com';">Google</button>
</noscript>
</p>
<iframe name='frame' id='frame' width='600' height='500'></iframe>
However, because the button needs JavaScript in order to work, the <noscript> section cannot use buttons unless you also use PHP or another server side language to refresh the page with the iframe loaded.
The iframe has a size of 600x500. Change this to whatever you want it to be.

In short, that will show buttons for most people, and text links for people that do not have JavaScript enabled on their browser.
You can add new links by copying the existing ones and modifying them to point to the new locations and so forth.



...Also, I've removed bugs and typos that have accumulated through different people helping you. It is HTML, not XHTML. If you know what I'm going on about, change it if you prefer. If you don't, then it will be fine as it is.
 

PacersForever

New Member
Messages
21
Reaction score
0
Points
0
Thanks man thats exactly what i was looking for. Is there a possibility for one of them to automatically open once you run the code ?
 

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
Of course!
Change the last line into something like this:
HTML:
<iframe name='frame' id='frame' width='600' height='500' src='http://www.google.com'></iframe>
 
Top