由于动态iframe而导致的ReactJS Google RecaptCha错误
有关文档的更多问题,因为React不记录此行为 ReactJS抛出错误,在ComponentDidMount()之前停止执行JS: 这是由于元素的内容在呈现服务器端和客户端之间不同造成的。 这可能是由以下来自Google Recaptcha的片段引起的,其中iFrame的内容会更改每个请求:由于动态iframe而导致的ReactJS Google RecaptCha错误,iframe,reactjs,recaptcha,Iframe,Reactjs,Recaptcha,有关文档的更多问题,因为React不记录此行为 ReactJS抛出错误,在ComponentDidMount()之前停止执行JS: 这是由于元素的内容在呈现服务器端和客户端之间不同造成的。 这可能是由以下来自Google Recaptcha的片段引起的,其中iFrame的内容会更改每个请求: var MyForm = React.createClass({ ... render: function() { return ( <iframe s
var MyForm = React.createClass({
...
render: function() {
return (
<iframe src="https://www.google.com/recaptcha/api/fallback?k=SECRETKEY"
frameBorder="0" scrolling="no"
style={{width: "302px", height: "422px", borderStyle: "none"}} >
</iframe>
...
var MyForm=React.createClass({
...
render:function(){
返回(
...
解决方案是危险地将iframe设置为内部html,这样react就不会比较呈现的版本
renderNoscriptCaptcha: function() {
if(!this.state.isBrowser) {
return {__html:
'<div style="width: 302px; height: 482px; line-height: 0">\
<iframe src="https://www.google.com/recaptcha/api/fallback?k=SECRETKEY" frameborder="0" scrolling="no" style="width: 302px; height: 422px; border-style: none" >\
</iframe>\
<div style="height: 60px; border-style: none; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px">\
<textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px; resize: none; line-height: 24px; font-size: 11px" >\
</textarea>\
</div>\
</div>'
}
}
},
render: function() {
return (
<div dangerouslySetInnerHTML={this.renderNoscriptCaptcha()}></div>
renderNoscriptCaptcha:function(){
如果(!this.state.isBrowser){
返回{uuuuhtml:
'\
\
\
\
\
\
\
'
}
}
},
render:function(){
返回(
renderNoscriptCaptcha: function() {
if(!this.state.isBrowser) {
return {__html:
'<div style="width: 302px; height: 482px; line-height: 0">\
<iframe src="https://www.google.com/recaptcha/api/fallback?k=SECRETKEY" frameborder="0" scrolling="no" style="width: 302px; height: 422px; border-style: none" >\
</iframe>\
<div style="height: 60px; border-style: none; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px">\
<textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px; resize: none; line-height: 24px; font-size: 11px" >\
</textarea>\
</div>\
</div>'
}
}
},
render: function() {
return (
<div dangerouslySetInnerHTML={this.renderNoscriptCaptcha()}></div>