Button or Link That Changes Page in Iframe

痴心易碎 提交于 2019-12-05 06:09:01

问题


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!


回答1:


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



回答2:


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>



回答3:


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>​


来源:https://stackoverflow.com/questions/10524990/button-or-link-that-changes-page-in-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!