相关疑难解决方法(0)

在Gatsby React页面中使用<script>添加原始HTML

我正在尝试将外部嵌入代码添加到我的Gatsby页面.

我目前正在使用

import React from 'react'
import Link from 'gatsby-link'


let test ="<script type='text/javascript'>
(function(d, s) {
    var useSSL = 'https:' == document.location.protocol;
    var js, where = d.getElementsByTagName(s)[0],
    js = d.createElement(s);
    js.src = (useSSL ? 'https:' : 'http:') +  '//www.peopleperhour.com/hire/1002307300/1213788.js?width=300&height=135&orientation=vertical&theme=light&rnd='+parseInt(Math.random()*10000, 10);
    try { where.parentNode.insertBefore(js, where); } catch (e) { if (typeof console !== 'undefined' && console.log && e.stack) { console.log(e.stack); } }
}(document, 'script'));
</script>"

const ContactPage = () => (

    <div>
        <h1>ContactPage</h1>
        <div
            dangerouslySetInnerHTML={{ __html: test }}
          />
    </div> …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs gatsby

12
推荐指数
2
解决办法
1万
查看次数

标签 统计

gatsby ×1

javascript ×1

reactjs ×1