Can I pop up alert in javascript using php

前端 未结 1 506
攒了一身酷
攒了一身酷 2021-01-29 08:36

I want to trigger javascript alert using PHP. Is it possible

I want to use it in head section, for displaying it at load time.


    

        
相关标签:
1条回答
  • 2021-01-29 09:25

    Of course this is possible.

    All you are doing is outputting JavaScript, it's all the same thing.

    The only issue is that you are nesting <script> tags, which is an HTML error, so get rid of the tags in the echo string.

    <script type="text/javascript">
    <?php 
        $valid="valid";
        if(!isset($valid))
            echo "alert('Hi');";
    ?>
    </script>
    

    By the way, as i'm sure you already know, this specific code will ALWAYS echo the "alert('Hi');"

    0 讨论(0)
提交回复
热议问题