Edward Mccolins
Edward Mccolins

Reputation: 13

Hidding iframe if specific value?

I want to hide iframe if there is no $content present.

<div class="video">
    <iframe width="600px" height="400px" src="'.$content.'?autoplay=1" frameborder="0" scrolling="no" allowfullscreen style="visibility:hidden;" onload="this.style.visibility=\'visible\';"></iframe>
</div>

In my case if $content is not present, iframe loads src="?autoplay=1"

Upvotes: 1

Views: 79

Answers (1)

Ant&#243;nio Almeida
Ant&#243;nio Almeida

Reputation: 10117

I think this will do the trick:

<?php
    // Test if variable is set and has content in it
    if( isset($content) && $content != "") {
        echo '<div class="video"><iframe width="600px" height="400px" src="'.$content.'?autoplay=1" frameborder="0" scrolling="no" allowfullscreen style="visibility:hidden;" onload="this.style.visibility=\'visible\';"></iframe></div>'
    }
?>

This way the iframe will not be printed in the html in case of no content.

Upvotes: 1

Related Questions