4

我正在尝试 (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/

任何帮助将不胜感激,这个问题超出了我的想象。

4

1 回答 1

6

这有效: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');

}
于 2013-09-04T20:28:15.660 回答