1 回答
TA贡献1900条经验 获得超5个赞
尝试这种超时和 preventDefault 的组合
window.addEventListener("load", function() {
document.getElementById("main-email-form").addEventListener("submit", function(e) {
const email = document.getElementById("main-email-field").value
// todo email validation
console.log(email,email.length);
if (email.length > 7) {
setTimeout(function() {
console.log("Download allowed");
// window.location = '/download-confirmation'; // uncomment after testing
}, 2000)
} else {
e.preventDefault(); // stop submission
console.log("Download failed");
// window.location = '/download-failed'; // uncomment after testing
}
})
})
<form id="main-email-form" class="email-form" method="POST" action="https://europe-west1-hoddle-website.cloudfunctions.net/registerUser" target="hiddenFrame">
<input id="main-email-field" class="main-email-field" type="email" name="email" placeholder="Email address">
<button type="submit" id="main-email-button" class="main-email-button">Download</button>
<input type="hidden" id="main-referralID-field" name="referralID" value="">
<input type="hidden" id="main-referralType-field" name="referralType" value="">
<input type="hidden" id="main-referralUserID-field" name="referralUserID" value="">
</form>
<iframe id="hiddenFrame" class="hiddenFrame" name="hiddenFrame" width="0" height="0" border="0" style="display: none;"></iframe>
添加回答
举报