0

My requirement is to add two script tags to my react component where the variables used in first script is referenced in second script.

<script type="text/javascript" language="javascript">
  var aax_size='300x250';
  var aax_pubname = XXXXXXXX;
  var aax_src=XXXXXX;
</script>

<script type="text/javascript" language="javascript" src="http://c.amazon-adsystem.com/aax2/assoc.js"></script>

Including the first script in index.html and including the second script in component enables the iframe to work properly. But using it in multiple components with different values is not working as the first script is in the index.html

Added the script in component using this way: https://stackoverflow.com/a/34425083/3991377

Mouleesh Guru
  • 55
  • 1
  • 10

1 Answers1

0

Something like this

const script = document.createElement("script");
document.body.appendChild(script);
script.innerHTML = "var aax_size='300x250'; var aax_pubname = XXXXXXXX; var aax_src=XXXXXX;"
Eugene Glova
  • 1,543
  • 1
  • 9
  • 12
  • We tried this way and it isn't working. The 'var' that goes as innerHTML is going as just string hence the second script is unable to find the variable. – Mouleesh Guru Nov 11 '19 at 14:08
  • try to play with order of adding script to the DOM, you should appendChild maybe then wait a bit with setTimeout to check it's evaluated – Eugene Glova Nov 11 '19 at 14:24