1

i am writing a php program to get images from folder and show it . i want to refresh it . i can not put tht javascript code in the php ?

<?php
$action = $_REQUEST['action'];
if ($action == "view"){
 $entry =$_GET['al']; 

the code for refreah

   echo '<script type="text/javascript">';
     function refresh(){
     document.images("img1").src="/latimage.php?device=$al&ref=" +  new    Date().getTime();
     var e = document.getElementById("blinker");
     e.style.visibility = ( e.style.visibility == "visible" )? "hidden" : "visible";
     setTimeout("refresh()", 3500);}
 </script>;
2
  • Take a look at your escaping. Then call refresh() from within your page Commented Jul 21, 2015 at 14:00
  • 1
    To answer the question: No, you can't do that. The JS needs to render as part of the HTML page. Read tutorials about HTML and how to include javascript so that you understand what you need to do. Commented Jul 22, 2015 at 1:31

3 Answers 3

4

You can use echo to output JavaScript code:

echo '<script type="text/javascript">',
    'function refresh() {',
        "document.images('img1').src='/latimage.php?device=$al&ref=' +  new    Date().getTime();",
        'var e = document.getElementById("blinker");',
        'e.style.visibility = ( e.style.visibility == "visible" )? "hidden" : "visible";',
        'setTimeout(refresh, 3500)',
    '}',
'</script>';
Sign up to request clarification or add additional context in comments.

1 Comment

He uses echo for the first line of the function then just types out JavaScript
0

Try Like ?> <script> location.reload(); </script> <?php

1 Comment

This would just infinitely reload the page.
0

Try To like

?>
<script>
setTimeout(
    document.images("img1").src="/latimage.php?device=$al&ref=" +  new    Date().getTime();
    var e = document.getElementById("blinker");
    e.style.visibility = ( e.style.visibility == "visible" )? "hidden" : "visible";
, 3500);
</script>
<?php

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.