【发布时间】:2021-08-08 16:10:04
【问题描述】:
我正在尝试检查 iframe src 是否已在第一次添加,以便它不会在第二次再次加载它。 iframe 是使用下面给出的函数激活的,我正在使用 jQuery 来检查这一点。不幸的是,每次触发函数时都会调用console.log("loaded");。我做错了什么?
<iframe id="iframe_01" style="
position: fixed;
margin: auto;
height: 100%;
width: 100%;
overflow: hidden;
z-index: 10;
display: none;
">
</iframe>
<script>
function Activate_iFrame() {
//iframe start
let iframe_01 = document.getElementById("iframe_01");
iframe_01.style.display = 'Block';
if ($("#iframe_01").find("iframe").contents().find("body")) {
console.log("loaded");
iframe_01.src = "LINK TO WEBSITE";
}
}
</script>
【问题讨论】:
-
I am trying to check if the iframe src has been already added the first time so that it does not load it again in the second time.这与问题中的代码完全相反。问题中的代码是确定iframe的内容中是否已经存在body,然后将内容完全更改为另一个URL。您能否将问题编辑得更清楚。
标签: javascript html jquery iframe