0

I have attached the code which i am using and while loading the page it is giving me error saying

Cannot contact reCAPTCHA. Check your connection and try again.

Please be remember I'm not going to use any server side code. My website is having simple html.

<html>
<head>
<title>reCAPTCHA demo: Explicit render after an onload callback</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<div class="g-recaptcha" data-sitekey="my_site_key"></div>
</body>
</html>
user9405863
  • 1,506
  • 1
  • 11
  • 16
  • _“Please be remember I'm not going to use any server side code. My website is having simple html.”_ - what sense is using a CAPTCHA supposed to make in the first place then? // Are you testing this by calling the document this is in via `http(s)://` in the browser, or are you just opening the file via the local file system? – CBroe Apr 05 '18 at 07:27
  • "what sense is using a CAPTCHA supposed to make in the first place then?" - I have contact us form and sending the details using web service so hope you understand why I need to put the captcha. Right now i am trying with the dummy html and trying to open the file via local file system. – Palash Agrawal Apr 05 '18 at 08:24
  • _“I have contact us form and sending the details using web service so hope you understand why I need to put the captcha”_ - so the web service is going to validate this captcha then? (Because if not, the whole thing is pointless to begin with.) _“Right now i am trying with the dummy html and trying to open the file via local file system”_ - then trying to embed external resources like jQuery using `//...` won’t work, and your browser console should have alerted you to that fact already. – CBroe Apr 05 '18 at 08:27
  • " web service is going to validate this captcha then?" - I don't know we can verify the captcha using webservice or not. That's why i raised the question because i don't know how to implement captcha in html page without using any server side code. Also, can you please suggest if you have any other idea to implement captcha on html page? – Palash Agrawal Apr 05 '18 at 08:38
  • Then this makes no sense to begin with. The webservice would need to refuse to actually send out an email, when it receives bogus data. You would need their active cooperation in checking the CAPTCHA to begin with, otherwise I will just send my data to the same endpoint without even using your form. – CBroe Apr 05 '18 at 08:41

1 Answers1

1

In short you can't. You have to send your site key, secret key and response to the Google API to verify it.

However there is a solution to check if the captcha is filled. When a user solves the captcha there is a element which gets filled named g-recaptcha-response.

With some javascript you can check if the user has solved the captcha.

var response = grecaptcha.getResponse();

if(response.length == 0)
    //reCaptcha not verified

else
    //reCaptch verified

However this solution is not a save one. If someone just changes the dom so it looks like the element g-recaptcha-response is filled it will pass your validation. To be absolute sure the captcha is solved you have to send a API request to Google.

EDIT: Also this question has been asked before (multiple times).
How can I validate google reCAPTCHA v2 using javascript/jQuery?

Frank Groot
  • 560
  • 6
  • 21
  • This kind of question have been asked multiple times but no one answered it correctly as you can see it in the link shared by you. Also my question is slightly different, i'm not coming to response however i'm saying at the time of page load it's showing me error. So do you have any solution to implement captcha on simple html page? As you know we are the developer we never say 'We Can't'. – Palash Agrawal Apr 05 '18 at 08:30
  • I implemented the same and it's working fine. Later i will share the code for the same. – Palash Agrawal Jun 26 '18 at 06:03