r/learnreactjs • u/CatViridarium • Oct 25 '22
How to execute/use JS scripts that are within <script> tags?
I'm using a CRM called Zendesk and (I think) the only 'good' way to use the API is through something like the snippet below, the thing is that I need to execute a script (change the Live Chat widget to a Contact Form widget) on a button onClick but I don't see how to make this happen.
<script type="text/javascript">
zE('webWidget', 'setLocale', 'fr');
</script>
3
Upvotes
3
u/TacoDelMorte Oct 25 '22
Anything in a script tag executes when the page loads. Are you trying to run the function “zE” on a button click?
4
u/TacoDelMorte Oct 25 '22
You should probably start with JavaScript basics. That’s not how JavaScript is supposed to work. You can’t call a “script” to run after the page is done loading completely (well, you can, but let’s not go there as that’s a whole can of worms). You need to be calling a function.
If the function fails when added to a button’s click event, then that function is the problem. You need to look into the Zendesk APIs to see how to accomplish this properly.
Edit: meant to reply to your reply and not the main thread