javascript - 如何自动加载 iframe 元素

标签 javascript jquery html iframe

我有一个投资组合页面,其中嵌入了大约 12 个 iframe 元素。我想知道是否有一种方法可以缓存或自动加载 iframe 元素,这样我就不需要在每次加载网站时都重新加载。

这是我的 iframe 元素的样子:

<iframe src="http://iframe.url" width="300" height="600" frameborder="0"></iframe>

iframe 元素包含横幅广告,由图像、HTML 和 JS 代码组成。请让我知道如何完成这项任务。感谢您的帮助!

最佳答案

我在这里引用了这些信息。如果我明白你想要什么,这看起来很有希望。

Friendly Iframe

This technique is for ads. It's not really an iframe loading technique, but more of a way to use an iframe to hold ads. The magic is not in how the iframe is loaded, but in how the main page, the iframe and ad codes work together. It works like this:

  1. 创建一个 iframe。将源设置为来自同一域的小型静态 html 页面

  2. 在 iframe 内,设置 JavaScript 变量 inDapIF = true 以告知广告它是在友好的 iframe 内加载的

  3. 在 iframe 中,创建一个以广告 url 作为源的脚本元素。像普通的 JavaScript 广告一样加载广告

  4. 广告加载完毕后,调整 iframe 的大小以适应广告的尺寸。

友好的 iframe 适用于所有浏览器。

列出了其他技术,但这似乎适合您的用例。在 Iframe loading techniques and performance 查看其他方法

如果您想要一种强制 iFrame 重新加载的方法,这里有一个 SO 答案。 How to force an iFrame to reload once it loads

关于javascript - 如何自动加载 iframe 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42077366/

相关文章:

javascript - 如何在 JQuery 中使用替换语句但排除一个类?

javascript - 显示/隐藏 div 取决于 viewpwort 中的特定类

java - 如何使用 servlet 更新 JSP 中的值?

javascript倒计时回显错误的时间

javascript - 使用 jQuery.each() 确保输入属于某种类型

javascript - 正则表达式接受至少一个字母数字字符和一个特殊字符

javascript - 在 HTML 表中查找匹配值并突出显示它

javascript - Jquery 中的 Base64 编码

jquery - 使用 z 索引和位置 :fixed to make layered scrolling

javascript - 焦点在 IE 中不起作用