[英]HTML/Javascript Error with iframe, should be easy
Hey can someone help me with this code?嘿,有人可以帮我处理这段代码吗? I want to switch every x seconds the iframe source but the page doesn't switch the iframe.我想每隔 x 秒切换一次 iframe 源,但页面不会切换 iframe。
<!doctype html>
<html>
<head>
<meta meta charset="utf-8"/>
</head>
<body>
<iframe name="frame" id="frame" src="" style="position: absolute; height: 100%; width: 100%;"/>
<script type="text/javascript">
var iframes = document.getElementById("frame").value;
var index = 0;
var urls = ['link1', 'link2', 'link3'];
var interval = window.setInterval(function(){
if(index == urls.length){
if(){
index = 0;
}
iframes.src = urls[index];
}
}, 3000);
interval();
</script>
</body>
</html>
Here is your solution:这是您的解决方案:
<head>
<meta meta charset="utf-8" />
</head>
<body>
<iframe name="iframe" id="iframe" src="https://google.com" style="position: absolute; height: 100%; width: 100%;"></iframe>
<script>
var iframe = document.getElementById("iframe");
var index = 0;
var urls = ['link1', 'lnk2', 'link3'];
var interval = window.setInterval(() => {
console.log("hi")
if (index > urls.length) {
index = 0;
}
iframe.src = urls[index];
}, 3000);
</script>
</body>
</html>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.