要求不大,有一个 iframe,后面跟着 3 个按钮。 一旦我们点击button1,url 就会显示在 iframe 中,与第二个按钮相同。 这是我的代码,请帮忙。
function testCoverage(){
window.frames['idIfrm'].document.location.href = 'http://google.com';
}
function testCoverage1(){
window.frames['idIfrm'].document.location.href = 'http://yahoo.com';
}
这里是JsFiddle
最佳答案
请尝试这个代码,它在我看来工作正常,
<div>
<button><a href="http://www.computerhope.com/banners/banner.gif" target="iframe_a">Banner1</a></button>
<button><a href="http://www.computerhope.com/banners/banner2.gif" target="iframe_a">Banner2</a></button>
<button><a href="http://www.computerhope.com/banners/banner3.gif" target="iframe_a" onclick="closeWindow();">Banner3</a></button>
<div>
<iframe src="http://www.computerhope.com/banners/banner3.gif" name="iframe_a" width="900" height="350px" id="iframe" frameborder="0" scrolling="no" style="margin-left:15px;margin-bottom:15px;border:none;">
</iframe>
</div>
</div>
关于javascript - 使用 javascript 在 Iframe 中显示 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21286586/