I am trying to include a script tag with some code inside based on an environment variable on a react project.
Let's say that I want the following code to load if the certain env variable is matched.
<script type="text/javascript">
var something = function() {
// some code
}
something()
</script>
I can access the value of evn variable in the HTML file so I could create a script tag using document.createElement('script') dynamically based on the value but that way I am only able to create a script tag but not content inside the script tag. Is there any way I can create the script tag and also insert some code inside that script tag?
I basically want to load the script tag above including the code inside on domcontentloaded event.
importyour script instead of creating DOM element with script. See importdocument.createElement('script')by setting itstextContentproperty...