Passing variable via include?

F

Fred Lazy

is it possible to pass a variable via a searchquery (as in after the
question mark) of an include, from an html file? Something like: ..

<script ... src="include.js?green">

... and the in the "include.js" file pick the value up:

if ( searchquery =="green"){
do something green
}

Or would it be done by some different method, if at all possible? I.e. to
set a variable from the <script src=..> level of the function call.
 
A

Aaa aaa

Fred said:
is it possible to pass a variable via a searchquery (as in after the
question mark) of an include, from an html file? Something like: ..

<script ... src="include.js?green">

.. and the in the "include.js" file pick the value up:

if ( searchquery =="green"){
do something green
}

Or would it be done by some different method, if at all possible? I.e. to
set a variable from the <script src=..> level of the function call.

## first js script:
-----
<script type="text/javscript" src="include.php?green=1"></script>
-----
## server-side php script 'include.php':
-----
<?php header("Content-type: text/javascript"); ?>

var green = '<?=isset($_GET['green']) ? $_GET['green'] : 'null'?>';

if ( green == 1 ) ....
-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top