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. Link to comment https://forums.phpfreaks.com/topic/125838-can-i-pass-a-parameter-when-i-call-a-javascript-file/ 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> Link to comment https://forums.phpfreaks.com/topic/125838-can-i-pass-a-parameter-when-i-call-a-javascript-file/#findComment-650827 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 ... Link to comment https://forums.phpfreaks.com/topic/125838-can-i-pass-a-parameter-when-i-call-a-javascript-file/#findComment-650841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.