Jump to content

Can I pass a parameter when I call a Javascript file


garry27

Recommended Posts

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.

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 ...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.