0

I am trying to use a external third party script file form outgrow.co in my website.My website is based on reactjs. The script file is supposed to generate a button.I have tried this script with html code and it works fine.But its not working for my reactjs code. This is the code i want to add:

 <div>
                <div id='5cbead6c7771f625d56e46f0' data-embedCookieDays='10' data-embedScheduling='false' data-embedTimed='true' data-embedExit='false' data-embedTimeFormat='0' data-embedTimeValue='5' data-embedBorderRadius='0' data-embedFontSize='13' data-textcolor='#ffffff' data-bgcolor='#fb545b' data-prop='outgrow-p' data-type='outgrow-b' data-url='https://arafathossain571.outgrow.us/5cbead6c7771f625d56e46f0?q=1' data-text='Get Started'></div>
                <script src='//dyv6f9ner1ir9.cloudfront.net/assets/js/nploader.js'></script><script>initIframe('5cbead6c7771f625d56e46f0');</script>
            </div>

here is what i tried:

 componentDidMount () {



        const script = document.createElement("script");


        (function(){

            <div>
                <div id='5cbead6c7771f625d56e46f0' data-embedCookieDays='10' data-embedScheduling='false' data-embedTimed='true' data-embedExit='false' data-embedTimeFormat='0' data-embedTimeValue='5' data-embedBorderRadius='0' data-embedFontSize='13' data-textcolor='#ffffff' data-bgcolor='#fb545b' data-prop='outgrow-p' data-type='outgrow-b' data-url='https://arafathossain571.outgrow.us/5cbead6c7771f625d56e46f0?q=1' data-text='Get Started'></div>
                <script src='//dyv6f9ner1ir9.cloudfront.net/assets/js/nploader.js'></script><script>initIframe('5cbead6c7771f625d56e46f0');</script>
            </div>
        })();


        document.body.appendChild(script);
    }

1 Answer 1

1

You should do this like this:

componentDidMount () {
  const script = document.createElement("script")

  script.src = "//dyv6f9ner1ir9.cloudfront.net/assets/js/nploader.js"
  script.async = false
  script.onload = () => {
    // you can append your div here
  }
  document.body.appendChild(script)
}
Sign up to request clarification or add additional context in comments.

3 Comments

Where should i add rest of the script.This One- <script>initIframe('5cbead6c7771f625d56e46f0');</script> should i declare it in another variable?
in `script.onload = () => { }
really sorry.i am still not getting it.should it be like this? script.onload = () => { <script>initIframe('5cbead6c7771f625d56e46f0');</script> <div> <div id='5cbead6c7771f625d56e46f0' '.......></div></div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.