Skip to content Skip to sidebar Skip to footer

React Native With Recatpcha

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

Solution 1:

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.com' // <-- SET YOUR DOMAIN HERE
    }}/>


getWebviewContent(){
    var originalForm = '<!DOCTYPE html><html><head><script src="https://www.google.com/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; 
}

Post a Comment for "React Native With Recatpcha"