N
N
newaitix2018-02-22 17:32:27
JavaScript
newaitix, 2018-02-22 17:32:27

Get query string in js file?

<script type="application/javascript" src="checkout.js?a=5 "></script>

If we are talking about a php file by going to /checkout.php?a=5 in the checkout.php file we can ask $_SERVER['QUERY_STRING'] and get that QUERY_STRING.
If we load the script as above, allegedly passing QUERY_STRING into it, then all we can do is parse the entire code of the document and find this script tag in it and see what query string it has.
As far as I understand, we do not recognize the query string through location. right ?
Or are there methods other than source code parsing?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
newaitix, 2018-02-22
@newaitix

I came up with the solution myself. Upload the script to the php. For example so

<?
$sf=$_SERVER['QUERY_STRING'];
header("Content-Type: application/javascript; charset=utf-8");
?>
var test="<?=$sf?>";
alert(test);

include this file in the header
Output // a=5

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question