【问题标题】:Iframe Load Too FASTiframe 加载太快
【发布时间】:2020-03-17 20:55:20
【问题描述】:

我设置脚本来加载我的 iframe,但我看到该脚本加载到快速 iframe 内容,我不知道如何设置为后台加载所有 css 图像内容,然后显示完整的 iframe 内容?

我的代码:

<style>
#test123 {
  display: none;
}
</style>
<script>
jQuery(document).ready(function( $ ){
$('iframe').on('load', function() {
    jQuery("#test123").css("display","block");
},)
});
</script>
<iframe id="test123" src="https://www.mydomain.co/iframe" height="200" width="300"></iframe>

【问题讨论】:

  • iframe 是否动态加载内容?没有任何事件会自动等待。
  • 等待它的唯一方法是在 iframe 完成加载所有内容后使用 postMessage()
  • 那是java脚本?我如何在我的代码中实现你能不能试着写代码让我明白你的意思? @Barmar

标签: javascript jquery html iframe


【解决方案1】:

为什么不尝试使用 setTimeOut 函数来延迟 iframe?不花哨,但应该可以。

<script>
jQuery(document).ready(function( $ ){
   $('iframe').on('load', function() {
      setTimeout(function () {
         jQuery("#test123").css("display","block");
      }, 2000); // 2 seconds
   },)
});
</script>

【讨论】:

  • 问题是在其他国家/地区示例“印度尼西亚或澳大利亚”需要超过 8 秒才能加载该 iframe。我想制作脚本,当页面 100% 加载时显示在我的博客文章@DiegoGraziano
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-10
  • 2017-08-12
  • 1970-01-01
  • 2014-04-28
  • 1970-01-01
  • 2020-03-21
  • 1970-01-01
相关资源
最近更新 更多