表单提交到新标签页,并重定向当前窗口无法在Chrome / Safari中运行

时间:2013-09-04 20:02:53

标签: jquery forms google-chrome redirect onclick

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

你可以在这里尝试代码---&gt; http://jsfiddle.net/GjyMd/7/

任何帮助都会受到赞赏,这个问题已经过去了。

1 个答案:

答案 0 :(得分: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');

}