问题
I have an i frame which has a src called map.php.
<iframe src= "map.php " ></iframe>
Inside map.php i have a variable called map. I want to change the value of "center " inside the map variable to something new when the src load up
map.php (javascript)
var map = new mapboxgl.Map({
center: [115.83333, -32.01667],
});
So my question is whether i can pass some parameter values along with src = map.php to change the center value
example. ( Just my concept )
<iframe src= "map.php/parameter center[new values] " ></iframe>
回答1:
you can pass values in query param by constructing the url like this:
map.php/parameter?cx=115.83333&cy=-32.01667
Again in the php script you can access these values from query params using
$_SERVER['QUERY_STRING']
. Just parse,extract and use the values inside php file.
回答2:
What @diwakersurya said was right , but you had to use the GET. I am posting a full answer for anyone who is stuck.
php
$str1 = $_SERVER['QUERY_STRING'];
$x = $_GET['cx'];
$y = $_GET['cy'];
来源:https://stackoverflow.com/questions/66057989/change-javascript-variable-value-by-passing-new-values-inside-url-get-request