我刚刚在登录页面添加了一个电子邮件注册表单,它运行正常(使用firebase作为后端顺便说一句)。但是,我想重定向到" thankyou.html "页面或在提交时出现弹出谢谢消息。
我怎样才能让它发挥作用?我知道这可能很容易,但我是新手。
这是我正在使用的代码。在html中包含此脚本:
`<script>
var signupForm = document.getElementById('signup-form');
var signupSuccess = document.getElementById('signup-success');
var signupError = document.getElementById('signup-error');
var signupBtn = document.getElementById('signup-button');
var onSignupComplete = function(error) {
signupBtn.disabled = false;
if (error) {
signupError.innerHTML = 'Sorry. Could not signup.';
} else {
signupSuccess.innerHTML = 'Thanks for signing up!';
// hide the form
signupForm.style.display = 'none';
}
};
function signup(formObj) {
// Store emails to firebase
var myFirebaseRef = new Firebase("https://crowdfluttr.firebaseio.com/signups");
myFirebaseRef.push({
email: formObj.email.value,
}, onSignupComplete);
signupBtn.disabled = true;
return false;
}
`
同样在Html:
<div class="signup">
<p id="signup-success" class="text-success" role="alert"></p>
<p id="signup-error" class="text-danger"></p>
<form class="signup-form form-inline" id="signup-form" role="form" onsubmit="return signup(this)">
<input class="form-control" style="width:250px" name="email" type="email" placeholder="Your email goes here!" required>
<button class="btn btn-info" id="signup-button" type="submit" >Request Early Access</button>
</form>
任何帮助表示赞赏!
答案 0 :(得分:0)
您可以使用
重定向您的用户window.location.replace("thankyou.html");
您的代码看起来像这样:
function signup(formObj) {
// Store emails to firebase
var myFirebaseRef = new Firebase("https://crowdfluttr.firebaseio.com/signups");
myFirebaseRef.push({
email: formObj.email.value,
}, onSignupComplete);
signupBtn.disabled = true;
// Redirect user to thank you page
window.location.replace("thankyou.html");
return false;
}