“Comment ajouter JavaScript en php” Réponses codées

Comment ajouter JavaScript en php

//this is my code 

you can add javascript to your code by using the echo statement and rap all 
your javascript between "" and if there is "" in the javascript code
then add \ before any "", and for the php inside rap it with ''
  
  
<?php
  echo "<script>document.write(\"hello world\")</script>"
?>
  
//other example

<?php
  $a = 5;
  echo "<script>document.write('$a')</script>"
?>

//other example
  
<?php 
$TokenData = Auth::user();

echo "<script type=\"text/javascript\">
             localStorage.setItem(\"id\", '$TokenData->id');
             localStorage.setItem(\"name\", '$TokenData->name');
             localStorage.setItem(\"email\", '$TokenData->email');
      </script> ";
Wide-eyed Wryneck

Comment inclure JavaScript dans PHP

// simply echo the path anywehre in php you need

echo "<script src="script.js" type="text/javascript"></script>"
Himanshu Jangid

ajouter javascript aux fonctions.php

/****
  To get started, locate and open your functions.php file, 
  then copy and paste the following code snippet:
****/
function ti_custom_javascript() {
    ?>
        <script>
          // your javscript code goes here
        </script>
    <?php
}
add_action('wp_head', 'ti_custom_javascript');

/****
This code above will add JavaScript to your header. 
To apply it to a single post only, you can use the following:
****/
function ti_custom_javascript() {
  if (is_single ('3')) { 
    ?>
        <script type="text/javascript">
          // your javscript code goes here
        </script>
    <?php
  }
}
add_action('wp_head', 'ti_custom_javascript');
/****
Note that you’ll need to replace the 3 
in the above example with the post ID number 
to which you want to add the code. To locate 
that number, navigate to the post from your 
admin dashboard, and then click on Edit. In 
the browser bar’s URL, the ID number is the 
number next to “post=”:
CoderHomie

Réponses similaires à “Comment ajouter JavaScript en php”

Questions similaires à “Comment ajouter JavaScript en php”

Plus de réponses similaires à “Comment ajouter JavaScript en php” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code