2 回答
TA贡献1802条经验 获得超4个赞
你可以做这样的事情:
<a href="http://www.google.com/" onclick="return loadIframe(this.href);">Page 1</a>
<a href="http://www.apple.com/" onclick="return loadIframe(this.href);">Page 2</a>
<iframe name="frameid" id="frameid" src="http://www.microsoft.com/" frameborder="0">
Your browser doesn't support iframes.
</iframe>
function loadIframe(url) {
$("#frameid").attr('src',url);
return false;
}
TA贡献2003条经验 获得超2个赞
你在正确的轨道上。
这一行确实有效:
document.getElementById('myFrame').src = 'https://yournewurl.com';
不要在链接上使用 onclick 属性,而是尝试添加一个事件侦听器,如下所示:
document.getElementById('myLink').addEventListener('click', () => {
// change src attribute of iframe
document.getElementById('myFrame').src = 'https://yournewurl.com';
})
- 2 回答
- 0 关注
- 208 浏览
添加回答
举报