External JS file. js How to invoke a variable in a PHP file
If there is a init.js file, want to call the index.php file in the $language variable, how to use, thank you
------Solution--------------------
Writes $language to an HTML page, such as
JS get: var lang = document.getElementById ("lang"). InnerHTML;
------Solution--------------------
In fact, JS and html,css is the same thing, you can completely let the external JS file generated dynamically by PHP.
But your needs are a bit around, just want to calculate the language in index.php, so as long as index.php put this variable in the index.php generated page somewhere (a variable in the script tag/arbitrary DOM node of a property), Let Init.js go after the onload to fetch it.
------Solution--------------------
There are some ways, the key is that your demand is not fit.
You can even exist in the session, and then all JS files are made into PHP, let js.php read session.
Simply, do a separate PHP interface, Ajax directly to get the data in the session.
Again simple to die, direct index.php hair cookie,js directly from Document.cookie take value.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.