【发布时间】:2018-08-04 14:36:14
【问题描述】:
我正在尝试将外部嵌入代码添加到我的 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>
)
export default ContactPage
里面充满了语法错误。能否请您指出一种在反应组件中包含原始 sn-ps 的更好方法?
在 Gatsby 中是否还有一个地方可以添加所有其他脚本,例如自定义脚本、Google Analytics、图标字体、animate.js 以及我可能需要的任何其他内容?
感谢您的帮助
【问题讨论】:
标签: javascript reactjs gatsby