首页 > 解决方案 > 如果外部 .php 仅可用,则显示 iframe。其他:隐藏它

问题描述

如果没有要显示的内容(外部服务器提供的广告横幅),我想隐藏 iframe(例如包含 iframe 的 div)。这是我到目前为止所拥有的,但它不起作用。其他解决方案存在“跨域”问题。

iframe 默认隐藏,检查外部 .php 是否可用。如果是,请显示它。

<script>
$.get('https://www.external-example.com/subolder/myid.php', function(data, textStatus, jqxhr) {
    // make the ad visible
    $('#iframe-container').show();
});
</script>

<div id="iframe-container" style="visibility: hidden;">
<div style="display:inline-block;width:auto;height:auto;">
  <iframe src="https://www.external-example.com/subolder/myid.php" style="background-color: white;border: 0;height: auto;text-align:center;width: auto;max-height: 100%;" scrolling="no"></iframe>
</div>
</div>

*脚本示例来自:如果没有出现广告,如何隐藏 div

标签: iframe

解决方案


推荐阅读