garry27 Posted September 25, 2008 Share Posted September 25, 2008 Is it possible to pass a parameter into a Javascript file in the header when you call it in HTML like this: <script type='text/javascript' src='javascriptfilename.js?paramname=paramvalue'></script> If it is- how do I collect it in the javascript file? Thanks. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 25, 2008 Share Posted September 25, 2008 I don't believe so. Parameters are passed via URL. You could do this: <script type='text/javascript' src='javascriptfilename.js></script> <script type='text/javascript'>var paramname=paramvalue;</script> Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 25, 2008 Share Posted September 25, 2008 Or, if you are using some type of server-side language such as PHP, then you could do something like what you proposed, you would just call a PHP page instead of a js file Example <script type='text/javascript' src='filename.php?paramname=paramvalue'></script> Then your PHP JavaScript file could look something like this: <?php echo "var paramename = {$_GET['paramname']};\n"; ?> // continue javascript code normall here ... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.