javascript:如果external.php文件有..则隐藏div。。内联样式从不更改

javascript:如果external.php文件有..则隐藏div。。内联样式从不更改,javascript,Javascript,故事:如果.php被删除或类似,则隐藏iframe。所以我试图隐藏包含iframe的div。客户A的网站可以从我的网站(外部网站)生成视频。但是如果视频被删除,它应该隐藏完整的iframe(div)。如果视频不可用,完整的php将被删除或重命名 隐藏如果是外部文件(我想使用iframe) 不可用或命名为.php?=123456或没有这是我再次运行您的代码的方式,因此您可以尝试: <div id="hide-me" style="display: none;"> <ifr

故事:如果.php被删除或类似,则隐藏iframe。所以我试图隐藏包含iframe的div。客户A的网站可以从我的网站(外部网站)生成视频。但是如果视频被删除,它应该隐藏完整的iframe(div)。如果视频不可用,完整的php将被删除或重命名

隐藏
如果是外部文件(我想使用iframe)
不可用或命名为.php?=123456或没有
这是我再次运行您的代码的方式,因此您可以尝试:

<div id="hide-me" style="display: none;">
    <iframe style="display: none;" id="id-in-external-php" src="https://www.external-website.com/subfolder/1250.php" style="background-color: white;border: 0;height: auto;text-align:center;width: auto;max-height: 100%;" scrolling="no"></iframe>
</div>

<script>
  const yourFunctionName = () => {
    const anyname = document.getElementById("hide-me");
    const frameId = document.getElementById("id-in-external-php");
    const check = frameId.contentDocument.body.children
    const c = check[0].innerText;
    if(c.startsWith('Cannot')) {
      anyname.style.display="none";
      frameId.style.display="none";
    } else {
      anyname.style.display="block";
      frameId.style.display="block";
    }
  }
  window.addEventListener("load", yourFunctionName, false);
</script>

constYourFunctionName=()=>{
const anyname=document.getElementById(“隐藏我”);
const frameId=document.getElementById(“外部php中的id”);
const check=frameId.contentDocument.body.children
常量c=检查[0]。innerText;
if(c.startsWith('Cannot')){
anyname.style.display=“无”;
frameId.style.display=“无”;
}否则{
anyname.style.display=“block”;
frameId.style.display=“block”;
}
}
addEventListener(“加载”,函数名,false);

我没有看到您在哪里调用了该函数,所以在窗口加载时调用了我的函数

我在中删除了id“id in external php”,但我仍然缺少什么?是否应更改为显示:none?external.php文件:这是iFrame的内容只有在src为“”时,iFrame内容才会被隐藏。例如,将其更改为“”,您将注意到iframe内容将被隐藏。我编辑了主代码,只需最初隐藏div并通过Javascript显示它,将external.php的文件名从1250.php更改为deleted1250.php。仍然会导致和iframe:Not Found在该服务器上找不到请求的URL。我将查看在更改真实路径名时是否出错。但是我想,没有。我也尝试了最后编辑的主代码。重命名,结果相同。显示:block和iframe,其中:未找到请求。。
<div id="id-in-external-php">this is content for the iframe</div>
<div id="hide-me" style="display: none;">
    <iframe style="display: none;" id="id-in-external-php" src="https://www.external-website.com/subfolder/1250.php" style="background-color: white;border: 0;height: auto;text-align:center;width: auto;max-height: 100%;" scrolling="no"></iframe>
</div>

<script>
  const yourFunctionName = () => {
    const anyname = document.getElementById("hide-me");
    const frameId = document.getElementById("id-in-external-php");
    const check = frameId.contentDocument.body.children
    const c = check[0].innerText;
    if(c.startsWith('Cannot')) {
      anyname.style.display="none";
      frameId.style.display="none";
    } else {
      anyname.style.display="block";
      frameId.style.display="block";
    }
  }
  window.addEventListener("load", yourFunctionName, false);
</script>