0

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)

Community
  • 1
  • 1
d_Sotero
  • 23
  • 1
  • 5

3 Answers3

1
<?php
    $line = file('alert.txt');
    $valrec= $line[0]; 
    if($valrec=="1"){
?>
<script type="text/javascript">
    $.fancybox('<?php echo $valrec;?>');
</script>
<?php
    }
?>
HDT
  • 2,017
  • 20
  • 32
1

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
?>
JFK
  • 40,963
  • 31
  • 133
  • 306
0

Maybe something along the lines of this would work. Just echo the value of $valrec into your JavaScript so it can branch based on that value.

<?php
$line=file('alert.txt');
$valrec=$line[0];
?>

<script type="text/javascript">
         $(function() {
              if(<?php echo($valrec); ?> === 1) $.fancybox("fancy box");
              else alert("lame box");
          });
</script>

If alert.txt contains "1", the above code sends the following HTML to the browser.

<script type="text/javascript">
         $(function() {
              if(1 === 1) $.fancybox("fancy box");
              else alert("lame box");
          });
</script>

If alert.txt contains "100", it sends this.

<script type="text/javascript">
         $(function() {
              if(100 === 1) $.fancybox("fancy box");
              else alert("lame box");
          });
</script>
eric.christensen
  • 3,191
  • 4
  • 29
  • 35