Yash Vekaria
Yash Vekaria

Reputation: 2373

The embedded widget script unable to generate its html inside React env

I wanted to load a survey widget in the react project, where I create and execute the script in the head after dom gets loaded. But it is unable to generate its poll HTML.

Here is react demo in codesandbox

If I load the same script inside the specific element in the body without react env it works, here it's demo in jsbin

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <h1>Polldaddy Title</h1>
 <div id="pollDaddyInfo"> 
   <p>Poll should generate below this statememt</p>
   <script charset="utf-8" src="https://static.polldaddy.com/p/10962229.js"></script>
 </div>
  <h1>Polldaddy End</h1>
</body>
</html>

Help me to identify what could possibly go wrong?

Upvotes: 0

Views: 280

Answers (1)

rajabraza
rajabraza

Reputation: 363

There is nothing wrong with your implementation in either scenario (i.e. with and without react environment).

Actually, in react environment you're loading the script which is async operation and an script that is loaded asynchronously cannot write on the document with document.write which is happening here

https://docs.google.com/document/d/1v3qxRRU7aPs7rk_RwsDPDwuE22Yi1KG_oyKmmgD3lGY/edit?usp=sharing

For supporting my argument here is another thread on stack overflow

Upvotes: 1

Related Questions