您好我正在尝试自动刷新此div标签。它包含一个链接到窗口小部件的外部URL的iframe。我希望它每30秒刷新一次。只是好奇如何做到这一点。
<div id="my-content">
<iframe src="https://discordapp.com/widget?id=*****************&theme=dark" width="350" height="500" allowtransparency="true" frameborder="0"></iframe></div>
</div>
<script>
$(document).ready( function() {
$('div.index-right').eq(0).append($('div#my-content'));
});
</script>
我收到一条未捕获的异常错误,在下面评论过。这适用于在iframe中链接的外部站点,并且没有本地写入的数据以进行更新。 div只需要刷新。
答案 0 :(得分:0)
我认为这应该有效,假设您在页面上只有一个iframe。
setInterval(function(){
$('iframe')[0].contentWindow.location.reload(true);
}, 30 * 1000);
为了帮助您获得安全警告,请尝试以下建议:The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match
答案 1 :(得分:0)
试试这个:
<p>Enter a number between <strong>0</strong> and <strong>100</strong> and remember your number.</p>
<p>When ready press "Begin" and the computer will try to find your number.</p>
<input id="myNumber" style="width: 100px" />
<button id="guess" onclick="compGuess">Begin</button>
function compGuess()
{
if (document.getElementById("myNumber").value < 0 || document.getElementById("myNumber").value > 100 )
{
alert("Please enter a number between 0 and 100.");
}
else
{
var start = 0;
var stop = 100;
var middle = Math.floor(start + stop / 2);
var guess = document.getElementById("myNumber").value;
if (middle == guess)
{
alert("Your number is: " + middle);
}
else
{
while (start <= stop)
{
if (middle < guess)
{
start = middle + 1;
}
else if (middle > guess)
{
stop = middle - 1;
}
else
{
alert(middle);
}
alert("Your answer is : " + middle);
}
}
}
这只会使用名为 my-content 的ID刷新div。