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 關注
- 241 瀏覽
添加回答
舉報