Search code examples
javascriptphpjqueryfancybox-2

Open fancybox after condition with value read on .txt file


I want to open a fancybox automatically when I enter the website and the value read on the txt file is "1"
The content of fancybox it will be a iframe to another page (alert.php)

To read the value of txt I have this

<?php
$line = file('alert.txt');
$valrec= $line[0]; //if "1" the fancybox appear
?>

I have difficulties using what I have read.

Already Seen

Open fancyBox automatically?

Open fancybox from function

how to just open a fancybox window (not onclick)


Solution

  • Complementing previous answers, you could do :

    <?php
    $line = file('alert.txt');
    $valrec = $line[0]; //if "1" the fancybox appear
    if($valrec == 1){
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($){
        $.fancybox({
            href: "alert.php",
            type: "iframe"
        });
    }); //ready
    </script>
    <?php
    }; // closes if
    ?>