How to pass param to JS file?

B

brett

I need to pass a hard coded value to a JS file:

<script language="JavaScript" src="Tracking.js"
type="text/javascript"></script>

Neither of these methods work:

<script language="JavaScript" src="Tracking.js?someid=303"
type="text/javascript"></script>

or

<script language="JavaScript" src="Tracking.js"
type="text/javascript">var someid = 303;</script>

or

<script>var someid = 303;</script>
<script language="JavaScript" src="Tracking.js"
type="text/javascript"></script>

Any suggestions?

Thanks,
Brett
 
L

Lasse Reichstein Nielsen

brett said:
I need to pass a hard coded value to a JS file:

<script language="JavaScript" src="Tracking.js"
type="text/javascript"></script>

You can drop the "language" attribute. The "type" attribute is
sufficient and preferred.
Neither of these methods work:

How did you expect them to work?
What happened?

Just saying that it doesn't work does not give us much to go by.
<script language="JavaScript" src="Tracking.js?someid=303"
type="text/javascript"></script>

That doesn't do anything except send the parameter to the server.
The server might use that to put the value directly into the
returned script, but that takes server processing.
<script language="JavaScript" src="Tracking.js"
type="text/javascript">var someid = 303;</script>

No, a script with a "src" attribute should be empty. The content
isn't used.
<script>var someid = 303;</script>

Should be
<script language="JavaScript" src="Tracking.js"
type="text/javascript"></script>

and it should work ... in the sense that the variable is available
for the following script to use. Ofcourse the script needs to be
written to use the variable "someid".
Any suggestions?

I'd go for the last one.
/L
 
T

Thomas 'PointedEars' Lahn

Lasse said:
No, a script with a "src" attribute should be empty. The content
isn't used.

That is not entirely true. The content of such a `script' element is
intended to be an alternative in the case the referenced script resource
could not be accessed (this excludes 4xx and 5xx server responses) or the
`src' attribute is not supported accordingly (it was not defined before
HTML 4).


PointedEars
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top