show iframe if external .php is available only. else: hide it

左心房为你撑大大i 提交于 2020-01-25 10:20:08

问题


If there is no content to display (ad banner delivered by external server), i want hide the iframe (e.g the div that includes the iframe). This is what i have so far, but it is not working. Other solutions had the "cross-origin" problem.

Iframe hidden by default, check if external .php available. If yes, display it.

<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>

*script example from: How do hide div if ad does not appear

来源:https://stackoverflow.com/questions/59299717/show-iframe-if-external-php-is-available-only-else-hide-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!