How are variables injected into JavaScript in HTML?

206 Views Asked by At

I realised that I don't know how variables are injected into JavaScript in HTML. I would like to test overriding a clickTag variable which is simply a var in the main body of a JavaScript ( a default value ), but to override it with the injected variable.

Something like this >

somewhere.com/index.html?{"clickTag":"http://www.something.com"}

What's the best way to do that ? Pretty basic, but I've been used to having the DoubleClick Enabler handling that for me and I have not thought about how the data actually gets in, and how I could test it.

( for a basic php file, passing variables the simplest way, it would be work.php?play=good&balance=true etc but I'm not finding a question here for what I have asked )

Please also correct my terminology if it is bad or misleading. Thanks.

1

There are 1 best solutions below

0
On BEST ANSWER

Variables aren't injected into JavaScript.

A JavaScript program defines variables. It might get values to assign to them by accessing APIs (such as location in a web browser which would give you details of the URL of the page).

If you want to override the value of a variable in an existing program then you would need to change the source code of that program to write a new value to that variable between the point where it would normally be assigned and the point where it gets read back and used.