0

I'm sure this is simple but here is what I need to do:

I want to change a variable within the source url. Heres an example of what I'm trying to say:

<script type="text/javascript" src="url.com?lang=en&X=word1&;"></script>

This works fine, but I want the variable X to be elsewhere, like this:

<script type="text/javascript" src="url.com?lang=en&X&;">
X=word;
</script>

How do I go about doing this?

Edited by persianprez: n/a

2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by persianprez
0

are you saying that you want to "read" the "X" from the url and make it into a JS variable?

0

No, what I'm trying to do is make it so the "X" can be changed elsewhere in the code and call it within the URL

0

in that case you need to dynamically insert the script tag:

<html>
<head>
<script>
var X='hello';

function importScript(url){
 var headID = document.getElementsByTagName("head")[0];         
 var newScript = document.createElement('script');
 newScript.type = 'text/javascript';
 newScript.src = url;
 headID.appendChild(newScript);
}

window.onload=function(){
  importScript('url.com?lang=en&X='+X+'&');
};
</script>
</head>
<body>
</body>
</html>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.