I have a php variable called $myVar = "6542";
Where can I echo it before the </head>
tag of my site (and not trigger any html issues) in order to be able to pick the value up with javascript?
Ty
Throw it above your tag somewhere. Simple.
<script type="text/javascript>var myvar = '<?=htmlspecialchars($myVar);?>';</script>
It can be put anywhere on the page, not necessarily needing to be above
Just about anywhere (the HEAD contents is the best place), provided that you wrap it up with a <script>
tag:
<script>
var myVar = "6542";
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.