Common.jsfunction gourl (lang) {...// $_session[' language ']=lang this code in JS how to write? ...}
Reply to discussion (solution)
The interaction between JS and PHP is best done with Ajax
PHP is generally embedded in the JS, where is the JS write php ah, to the server support.
function Gourl (lang) {
...
...
}
JS to be associated with PHP, the general is to use the AJAX request, if it is in the JS load to get (take) session value, you can write in the JS code block If you want to load the page when the session is set, this with JS is OK, you can directly
main.inc.php
index.php
Display (' index.html ');? >index.html[code=php]
<title></title>
Propagation Jane NewComplex, complex, complex, complexCommon.jsfunction gourl (lang) {var url = document.location.href; var query = window.location.search.substring (1); var urls = url.replace (Window.location.hash, "). Split ("? "); var VARs = Query.split ("&"); var query = ""; for (Var i=0;i
Click index.html "Fan" switch language (complex)
I change $_session[' language ' at the same time I call Gourl ()
So I would like to add PHP code in JS, if the following will be an error, to find a solution
function Gourl (lang) {
...
...
}
1, the session variable is stored on the server side, the client cannot actively modify
2. You have location.href in gourl () = urls[0]+ "?" +query+window.location.hash; Jump
So you should do the session variable setting in the program file pointed to by Urls[0].
1, the session variable is stored on the server side, the client cannot actively modify
2. You have location.href in gourl () = urls[0]+ "?" +query+window.location.hash; Jump
So you should do the session variable setting in the program file pointed to by Urls[0].
After the jump is also to index.php->index.html execution of the Gourl () when the original link is added? Lang=xx to change the language
function Gourl (lang) {
var url = document.location.href;
var query = window.location.search.substring (1);
var urls = url.replace (Window.location.hash, "). Split ("? ");
var VARs = Query.split ("&");
var query = "";
for (Var i=0;i
var pair = Vars[i].split ("=");
if (pair[0]! = "Lang" && pair[0]! = "") {
query = query + pair[0] + "=" + pair[1] + "&";
}
}
query = query + "lang=" + lang;
Location.href = urls[0]+ "?" +query+window.location.hash;
}
I would like to create a gourl.php to replace the above in PHP how to implement this JS function
After changing the language, the page needs to be refreshed, and your original writing does not need to change
Your gourl.php is always going to output the content of the page like index.php. Does it seem cumbersome?