微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法将 <Script/> 标签附加到 <div> index.html react.js

如何解决无法将 <Script/> 标签附加到 <div> index.html react.js

嗨,我需要将下面的脚本附加到 react 的 index.html 中的 div 标签。我从后端 API 端获取此脚本

<style type='text/css'>
       .helpButton .uiButton {
        background-color: #005290;
        font-family: "Arial",sans-serif;
      }
    
       .helpButton .uiButton:focus {
        outline: 1px solid #005290;
      }
    </style>
    
    <script type='text/javascript' src='.min.js'></script>
    <script type='text/javascript'>
      var initESW = async function (gslbBaseURL) {
        embedded_svc.settings.samplesplayHelpButton = true; 
        embedded_svc.settings.language = ''; 
        
        
        embedded_svc.settings.enabledFeatures = ['LiveAgent'];
        embedded_svc.settings.entryFeature = 'LiveAgent';

        try {

          await embedded_svc.init(
            'https://test--sample.my.salesforce.com','https://sample-test.cs81.force.com/Surveys',gslbBaseURL,'111111111','DDC_test',{
              baseLiveAgentContentURL: 'https://test.salesforceliveagent.com/content',deploymentId: '111111111',buttonId: '111111111',baseLiveAgentURL: 'https://test.salesforceliveagent.com/chat',eswLiveAgentDevName: 'test_event',isOfflinesupportEnabled: true
            }
          );
        }
        catch (error) {
          console.log(error)
        }
      };

      if (!window.embedded_svc) {
        var s = document.createElement('script');
        s.setAttribute('src','https://test--sample.my.salesforce.com/embeddedservice/5.0/esw.min.js');
        s.onload = function () {
          initESW(null);
        };
        document.body.appendChild(s);
      } else {
        initESW('https://service.force.com');
      }
    </script>

我可以将上述脚本附加到 index.html react 的 div 标签但它不会在 UI 上呈现。 我写了下面的代码将数据附加到 index.html

var data = API call;
document.getElementById('webchat').innerHTML = data;

我的 index.html 有 ID 为“webchat”的 div 标签

<div id="webchat"></div>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。