如果iframe中没有网址,如何隐藏空的div文件?

时间:2019-03-23 07:49:33

标签: php html iframe

快速问题,如何在php中隐藏此代码:如果没有显示或“ src”中没有链接或未知?

问题是,因此.css中的<div class="resp-container">具有padding-top: 56.25%;。即使iframe为空,所有框上都有填充。

我希望你们的解释很清楚,如果有点难以解释,我感到抱歉。

要了解我的意思,这是我当前存在问题的网页:https://donpramis.com/timeline/

<div class="resp-container">
<iframe class="resp-iframe" src=(unknown) frameborder="0" sandbox="allow-same-origin allow-scripts" allowfullscreen="allowfullscreen"></iframe>
</div>

这是完整的代码:

<div class="container">
   <h3 align="center"><a href="">Timeline (Beta)</a></a></h3><br />
   <div class="panel panel-default">
    <div class="panel-heading">
                    <h3 class="panel-title">My Journey</h3>
                </div>
                <div class="panel-body timeline-body">
                 <div class="timeline">
                  <div class="timeline__wrap">
                   <div class="timeline__items">
                   <?php 
                   foreach($result as $row)
                   {
                   ?>
                    <div class="timeline__item">
                     <div class="timeline__content">
                      <h2><?php echo $row["year"]; ?></h2>                   
                      <p><?php echo $row["comment"];?></p>
                      <p><a href="<?php echo $row["website"];?>"><?php echo $row["Site_Description"];?></a></p> 

<div id="resp-container">
<iframe class="resp-iframe" src="<?php echo $row["iframe_video"];?>" frameborder="0" sandbox="allow-same-origin allow-scripts" allowfullscreen="allowfullscreen"></iframe>
</div>
<img class="img-responsive" src="<?php echo $row["timelime_image"];?>" alt="" />

                     </div>
                    </div>                                         
                   <?php
                   }
                   ?>
                   </div>
                  </div>
                 </div>
                </div>
   </div>
  </div>


3 个答案:

答案 0 :(得分:0)

您可以在检查src的值后将Div与iframe添加在一起。例如:

<?php if($row['iframe_video']!='' && $row['iframe_video']!='unknown') echo '<div id="resp-container">
<iframe class="resp-iframe" src="'. $row["iframe_video"].'" frameborder="0" sandbox="allow-same-origin allow-scripts" allowfullscreen="allowfullscreen"></iframe>
</div>'; ?>

答案 1 :(得分:0)

使用jQuery检查iframe中的内容。如果内容不存在,请使用hide()隐藏resp-container;

if(!$("#iframeid").contents().find("body").length) {

   $('.resp-container').hide();

}

答案 2 :(得分:0)

您首先需要验证数据。 要进行验证,您可以使用空支票if(empty($row["iframe_video"])函数。 代码在这里。

<div id="resp-container">
    <?php if (empty($row["iframe_video"]) || $row["iframe_video"] != 'unknown'): ?>
        <iframe class="resp-iframe" src="<?php echo $row["iframe_video"];?>" frameborder="0" sandbox="allow-same-origin allow-scripts" allowfullscreen="allowfullscreen"></iframe>
    <?php endif ?>
</div>