javascript - 在recaptcha中成功后如何重定向
问题描述
在验证码尝试成功后,我正在尝试将该人重定向到某个位置。我使用了这段代码,但这不起作用。
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script type="text/javascript">
if (grecaptcha.getResponse() == "success")
{
function Redirect()
{
window.location.href = "example.com";
}
setTimeout(Redirect,1000);
}
else alert("You can't proceed!");
</script>
<div data-type="image" class="g-recaptcha" data-sitekey="my-sitekey"></div>
我认为它不起作用,因为我不了解https://www.google.com/recaptcha/api/siteverify api。你能举一个代码的例子吗?我想在 recaptcha 成功后在 example.com 之后重定向,否则向他发送“您无法继续”
解决方案
The problem is, when the recaptcha returns 'success' you are creating a function called Redirect but you are not calling it, so you have to call the function after create it:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script type="text/javascript">
if (grecaptcha.getResponse() == "success") {
function Redirect() {
window.location.href = "https://www.youtube.com/";
}
Redirect()
setTimeout(Redirect, 1000);
} else alert("You can't proceed!");
</script>
<div data-type="image" class="g-recaptcha" data-sitekey="my-sitekey"></div>
Or you can delete the function and redirect directly Make sure you are adding the full url:
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script type="text/javascript">
if (grecaptcha.getResponse() == "success") {
window.location.href = "https://www.youtube.com/";
setTimeout(Redirect, 1000);
} else alert("You can't proceed!");
</script>
<div data-type="image" class="g-recaptcha" data-sitekey="my-sitekey"></div>
推荐阅读
- c++ - 即使在 CMake 中指定了我的标头,Visual Studio 怎么找不到我的标头?
- javascript - 我很想在 javascript 中将多个图像下载为 zip 文件
- android - 当我从 Xamarin.Android 中的静态快捷方式启动应用程序时,未安装应用程序
- reactjs - 使用公共 IP 访问在 Azure vm 中运行的 webapp 时出错
- angular - 根据单选按钮值动态禁用角垫单选复选框
- java - 非 html 方法 Spring MVC
- git - 排除 ftp-deploy 中的密钥故障
- c# - Xamarin Forms 在 Shell 页面内显示选取器
- http - 一个电子邮件应用程序使用不同的端口
- mongoose - Graphql 使用猫鼬解析信息