我想让它做3件事
- 提交到谷歌表单。 = 将我重定向到谷歌表单
- 打印此页。 = 当我单击"打印"或"取消"以打印页面时,它将然后
- 将我重定向到另一个页面女巫是主页
正在使用此代码,它有时有效,问题是当我单击提交时,我得到 2 个弹出窗口的第一个弹出窗口,并显示错误,显示"某些打印功能已禁用"单击确定将我重定向到第 1 页。 第二个弹出窗口是打印味精女巫要求我打印,当点击打印时将我重定向到第 2 页。所以说它可以工作,但由于该错误消息,如果我单击它以快速或如果我先单击打印按钮,它不会像我想要的那样重定向我。 我应该如何处理?
这是我正在使用的代码
<script type="text/javascript">
<!-- Print & Submit page -->
function Submit_print_google() {
window.print();
// Google form
var formElementsArray = document.getElementsByTagName('FORM');
if ( formElementsArray != null ) {
var formElement = formElementsArray[0];
document.getElementById('Google_form').name = 'NOVIEWSTATE';
formElement.action = 'https://docs.google.com/forms/d/1XXXXXXXXXXXXXX/formResponse';
window.location = 'http://link.com/HomePage';
formElement.submit();
} else {
redirect();
}
}
</script>
<script type="text/javascript">
function redirect(){
document.location = "http://link.com/homepage" }
}
</script>
<form id="Google_form" action="JavaScript:Submit_print_google()"
method="POST" id="ss-form" target="_self" autocomplete="off"
onsubmit="window.location = 'JavaScript:Submit_print_google()';">
First name<input name="entry.1234567789" class="ss-q-short" id="entry_1234567789" type="text">
Last Name<input name="entry.123456" class="ss-q-short" id="entry_123456" type="text" >
<input type="submit" style="float:right" value="Submit & Print Page" >
更新 当我单击打印的取消作业时,此代码有效,但在单击打印时不起作用。我需要它来处理取消和打印。
<script type="text/javascript">
<!-- Print & Submit page -->
function Submit_print_google() {
// Google form
var formElementsArray = document.getElementsByTagName('FORM');
if (formElementsArray != null) {
var formElement = formElementsArray[0];
document.getElementById('Google_form').name = 'NOVIEWSTATE';
formElement.action = 'https://docs.google.com/forms/d/xxx/formResponse';
formElement.submit();
// Redirect
redirect()}
}
</script>
<script type="text/javascript">
// Redirect
function redirect()
{window.print();
window.location = 'http://www.link.com/HomePage.html'; }
</script>
我什至尝试过这个。但是没有什么只适用于康塞尔
function redirect(){
if (window.print()) {
window.location = 'http://www.link.com/Home.page.html';
} else {
window.location = 'http://www.link.com/Home.page.html';
}
}
尝试在新标签页/窗口中打开打印网址。将当前页面重定向到您尝试将其重定向到的 URL。
我相信您遇到的问题是同一页面试图同时处理打印和重定向; 这不可能在一个页面中同时处理。因此,只有当您取消打印时,重定向才会起作用。
代码应该是这样的:
window.open('http://www.link.com/Home.page.html','_blank');