Is it possible to have buttons that change the iframe on your site ? Diagram below.
![]()
Is it possible to have buttons that change the iframe on your site ? Diagram below.
![]()
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:
But there's a parameter "target" too:HTML Code:<a href="http://forums.x10hosting.com/programming-help/url">
This would open the link in the frame (iframe / frameset) named "name".HTML Code:<a href="http://forums.x10hosting.com/programming-help/url" target="name">
eg.
HTML Code:<a href="http://www.google.com" target="frame">Google in frame.</a> <iframe name="frame" />
Last edited by marshian; 08-31-2008 at 09:38 AM. Reason: htt -> http
Real programmers don't document their code - if it was hard to write, it should be hard to understand.
Thanks !!! But it doesn't work with firefox
Firefox doesn't know how to open this address, because the protocol (htt) isn't associated with any program.
that's a typo in the example by marshian. Add a 'p' into the link so it reads:
HTML Code:<a href="http://www.google.com" target="frame">Google in frame.</a> <iframe name="frame" />
If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:
Or you could JS it.
HTML Code:<button onclick="document.getElementById('frame').src = 'http://www.google.com';">Google.com</button> <iframe id='frame' />
- When in doubt, refer to the PHP manual.
JS is good for this. However, make sure you use the following to ensure that it will work for more people:
HTML Code:<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'>
If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:
Ok I have this now
PHP Code:<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 by PacersForever; 08-31-2008 at 02:06 PM.
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.
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.HTML Code:<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>
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.
If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:
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 ?
Of course!
Change the last line into something like this:
HTML Code:<iframe name='frame' id='frame' width='600' height='500' src='http://www.google.com'></iframe>
If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts: