在IFRAME的网址onclick按钮之间切换

时间:2018-07-08 10:35:42

标签: javascript html css

通过单击按钮在IFRAME地址之间切换。

<iframe src="www.example.com"></iframe>


<div id="2">
<iframe src="www.wow.com"></iframe>

1 个答案:

答案 0 :(得分:1)

请参阅此处(运行代码):https://www.w3schools.com/code/tryit.asp?filename=FT3NWLA87A5A

function func(){
var url1 = document.getElementById("frame1").src;
var url2 = document.getElementById("frame2").src;
document.getElementById("frame1").src=url2;
 document.getElementById("frame2").src=url1;
}
<iframe src="https://www.w3schools.com" id="frame1">
  <p>Your browser does not support iframes.</p>
</iframe>
<iframe src="https://www.findertoday.com" id="frame2">
  <p>Your browser does not support iframes.</p>
</iframe>

<button onclick="func()">Switch</button>