我的目标是在提交表单时打开一个 paypal 页面,但什么也没有发生,所以我添加了没有记录任何内容的日志。
我的代码的第一个控制台日志出现了,但是函数内部的日志onSubmit()
没有出现,但我也知道该函数正在运行,因为google.script.run.processForm()
正在被调用并且也没有错误消息。
console.log("Page loaded, preparing to submit form");
window.onload = function() {
var form = document.querySelector('form');
console.log(form)
form.addEventListener('submit', onSubmit); // Listen for the submit event
}
function onSubmit(event) {
event.preventDefault();
alert("onSubmit() was called!");
console.log("Form submitted");
google.script.run
.withSuccessHandler(function(url) {
console.log("Redirecting to:", url);
if (typeof url === "string" && url.startsWith("https://")) {
window.open(url, "_self");
} else {
alert("Error: Invalid PayPal link.");
}
})
.processForm();
}
<form>
<iframe src="https://docs.google.com/forms/d/e/(private)/viewform?embedded=true" width="640" height="1169" frameborder="0" marginheight="0" marginwidth="0">Wird geladen…</iframe>
</form>