最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Native with reCATPCHA - Stack Overflow

programmeradmin3浏览0评论

I'm trying to implement the google reCAPTCHA in my react native app. I'm using a wrapped webview.

<WebView 
    javaScriptEnabled={true} 
    mixedContentMode={'always'} 
    style={{height: 200}} 
    source={{
        html: this.getWebviewContent()
    }}/>


getWebviewContent(){
    var originalForm = '<!DOCTYPE html><html><head><script src=".js"></script></head><body><form action="[POST_URL]" method="post"><input type="hidden" value="[TITLE]"><input type="hidden" value="[DESCRIPTION]"><input type="hidden" value="[URL]"><div class="g-recaptcha" data-sitekey="<My key>"></div><input type="submit" value="Send"/></form></body></html>'
    var tmp =  originalForm
        .replace("[POST_URL]", "http://localhost:3000/v1/video")
        .replace("[TITLE]", this.state.form.title)
        .replace("[DESCRIPTION]", this.state.form.description)
        .replace("[URL]", this.state.form.url); 

    return tmp; 
}

If I render it, it gives me the following error:

I have a theory that it doesn't want to cooperate since I'm running it as a "file" in the WebView and that you cannot add files as part of the domain in the Google dashboard.

Is there any way of either added file:// permissions in the reCAPTCHA dashboard of Google or any way of faking a domain, so that I can add that faked domain in the dashboard. Or am I pletely lost and the issue is something else?

I'm trying to implement the google reCAPTCHA in my react native app. I'm using a wrapped webview.

<WebView 
    javaScriptEnabled={true} 
    mixedContentMode={'always'} 
    style={{height: 200}} 
    source={{
        html: this.getWebviewContent()
    }}/>


getWebviewContent(){
    var originalForm = '<!DOCTYPE html><html><head><script src="https://www.google./recaptcha/api.js"></script></head><body><form action="[POST_URL]" method="post"><input type="hidden" value="[TITLE]"><input type="hidden" value="[DESCRIPTION]"><input type="hidden" value="[URL]"><div class="g-recaptcha" data-sitekey="<My key>"></div><input type="submit" value="Send"/></form></body></html>'
    var tmp =  originalForm
        .replace("[POST_URL]", "http://localhost:3000/v1/video")
        .replace("[TITLE]", this.state.form.title)
        .replace("[DESCRIPTION]", this.state.form.description)
        .replace("[URL]", this.state.form.url); 

    return tmp; 
}

If I render it, it gives me the following error:

I have a theory that it doesn't want to cooperate since I'm running it as a "file" in the WebView and that you cannot add files as part of the domain in the Google dashboard.

Is there any way of either added file:// permissions in the reCAPTCHA dashboard of Google or any way of faking a domain, so that I can add that faked domain in the dashboard. Or am I pletely lost and the issue is something else?

Share Improve this question asked Sep 1, 2017 at 6:10 Victor AxelssonVictor Axelsson 1,4661 gold badge15 silver badges33 bronze badges 2
  • Does it work if you set a domain with baseUrl? <WebView source={{ html: this.getWebviewContent(), baseUrl: 'http://your-domain.' }} – mihai1990 Commented Sep 1, 2017 at 11:03
  • Yes, that does work! Thanks a lot for your feedback. If you write a example solution I can set it as the accepted answer. – Victor Axelsson Commented Sep 4, 2017 at 6:18
Add a ment  | 

1 Answer 1

Reset to default 4

You can set a domain for your WebView by setting baseUrl in source prop:

<WebView 
    javaScriptEnabled={true} 
    mixedContentMode={'always'} 
    style={{height: 200}} 
    source={{
        html: this.getWebviewContent(),
        baseUrl: 'http://your-domain.' // <-- SET YOUR DOMAIN HERE
    }}/>


getWebviewContent(){
    var originalForm = '<!DOCTYPE html><html><head><script src="https://www.google./recaptcha/api.js"></script></head><body><form action="[POST_URL]" method="post"><input type="hidden" value="[TITLE]"><input type="hidden" value="[DESCRIPTION]"><input type="hidden" value="[URL]"><div class="g-recaptcha" data-sitekey="<My key>"></div><input type="submit" value="Send"/></form></body></html>'
    var tmp =  originalForm
        .replace("[POST_URL]", "http://localhost:3000/v1/video")
        .replace("[TITLE]", this.state.form.title)
        .replace("[DESCRIPTION]", this.state.form.description)
        .replace("[URL]", this.state.form.url); 

    return tmp; 
}
发布评论

评论列表(0)

  1. 暂无评论