我使用JavaScript代码加载iframe,但每次加载时都会闪烁。如何避免在加载iframe时闪烁?

这是我的代码

<script type="text/javascript">
  setInterval(function () {
  var iframe1 = document.getElementById("iframe1");

  iframe1.src = "frmChatRequest.aspx";
  }, 4000);
</script>

最佳答案

试试这个:

<script type="text/javascript">
  var myInterval = setInterval(function () {
  var iframe1 = document.getElementById("iframe1");
    if(iframe1.src == "frmChatRequest.aspx"){
        clearInterval(myInterval)
    }else{
        iframe1.src = "frmChatRequest.aspx";
    }
  }, 1000);
</script>

09-19 09:14