Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html form target _blank browser not allowed

Tags:

jquery

ajax

popup

I need to send a post request to paypal, but before sending the form I need to verify some inputs and the paypal page must be opened in a new tab or window (doesn't matter). I can't send the request in the same window because in the main page I have background ajax callbacks. So the ideea is can I send the request in a new window or tab?

In all major browesers this isn't allowed, browser keep blocking the request.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" id="paypal_form">
<input type='hidden' name='some_value' id='some_value' value='151' />
</form>

<div id='button_submit' onClick="verify_paypal_form();">SUBMIT !</div>

And now the ajax part:

function verify_paypal_form(){
   $.post('verify.php', { someValue : 'FOO' },
   function(data){
      if( data == 'OKAY' ) $('#paypal_form').submit();
   });
}
like image 418
Zbarcea Christian Avatar asked Feb 02 '26 12:02

Zbarcea Christian


1 Answers

set the target of form to iframe and try it. you can show that iframe as a content of new tab as well.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="myFrame" id="paypal_form">
<input type='hidden' name='some_value' id='some_value' value='151' />
</form>

<div id='button_submit' onClick="verify_paypal_form();">SUBMIT !</div>
<iframe id="myFrame" ...... set other attributes as required....></iframe>
like image 92
K D Avatar answered Feb 05 '26 04:02

K D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!