user1373771
user1373771

Reputation: 299

Button or Link That Changes Page in Iframe

I wish to make a link or button in a page that changes the page the iframe is on. It would be a local page:

idreesinc.com/iframe.html

and you can see what I have already here:

idreesinc.com/research

Help would be much appreciated as i have been looking for an answer for ages. Thanks!

Upvotes: 5

Views: 58234

Answers (4)

XPloRR
XPloRR

Reputation: 352

Create a button inside a link with its target pointing to the iframe name:

<iframe name="demo" src="site1.html"></iframe>
<a href="site2.html" target="demo"><button>site2</button></a>

Upvotes: 1

ofermc
ofermc

Reputation: 287

You can simply make an link with its target to the iframe name as follows:

<iframe name="demo" src="example.php"></iframe>

Your link in the parent will be:

<a href="newpage.html" target="demo">Change Link</a>

Upvotes: 19

Tina CG Hoehr
Tina CG Hoehr

Reputation: 6779

I'm using jQuery.

$("#mybutton").click(function(){$("#myiframe").attr("src", "http://www.yahoo.com/")});​

http://jsfiddle.net/ws2hm/1/

 #myiframe { width: 300px; height: 300px }

$("#mybutton").click(function(){$("#myiframe").attr("src", "http://www.yahoo.com/")});​

Text on main page
<button id="mybutton">Swap</button>
<iframe id="myiframe" src="http://www.bing.com/"></iframe>​

Upvotes: 0

Danilo Valente
Danilo Valente

Reputation: 11342

<script>
function setURL(url){
    document.getElementById('iframe').src = url;
}
</script>
<iframe id="iframe" src="idreesinc.com/research.html" />
<input type="button" onclick="setURL('URLHere')" />

Upvotes: 15

Related Questions