The form is sent to a new tab and redirects the current window that does not work in Chrome / Safari

I am trying (1) to submit the form to an external website, which should be launched in a new tab, and at the same time (2) redirect the browser window with the form to the page with gratitude.

My code works in Firefox and Internet Explorer and will execute either part (1) or part (2) in Chrome / Safari if I delete another part.

<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> 

Here you can try the code ---> http://jsfiddle.net/GjyMd/7/

Any help would be appreciated, this problem goes over my head.

+4
source share
1 answer

It works: 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'); } 
+6
source

Source: https://habr.com/ru/post/1500609/


All Articles