我正在尝试(1)将表单提交到应在新选项卡中启动的外部网站,同时(2)将带有表单的浏览器窗口重定向到感谢页面。
我的代码可以在 Firefox 和 Internet Explorer 中运行,并且如果我删除其他部分,则可以在 Chrome/Safari 中执行第 (1) 部分或第 (2) 部分。
<script>
function testfunc() {
alert('Submit Clicked');
jQuery('form#getaQuote').submit();
alert('Form submit attempted');
window.location.href = ('http://ct.athiel.ca');
alert('Redirect attempted');
}
</script>
<form id="getaQuote" action="http://www.winquote.net/complete.pl" target="_blank">
<input type="text" name="field1" />
<input type="button" value="Submit" onclick="testfunc()" />
</form>
您可以在这里尝试代码 ---> http://jsfiddle.net/GjyMd/7/
任何帮助将不胜感激,这个问题超出了我的范围。
最佳答案
这有效:jsFiddle
JavaScript:
function testfunc() {
alert('Submit Clicked');
setTimeout(function() {
window.location.href = ('http://ct.athiel.ca');
alert('Redirect attempted');
}, 1);
jQuery('form#getaQuote').submit();
alert('Form submit attempted');
}
关于jquery - 表单提交到新选项卡,并重定向当前窗口在 Chrome/Safari 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18622794/