0

I have been trying to figure this out for past few hours, I have form and when users will submit it,

new window popup will occur, however I want it delayed slightly, setting setTimeout did not work and I have no idea why.

example:

<form method="post" target="print_popup" action="https://example.com" onsubmit="window.open('about:blank','print_popup','width=1000,height=800');">
<input type="hidden" name="param" value="foobar">
<input id="1" type="submit" value="Submit request">
SecurityQuy
  • 15
  • 1
  • 6
  • That is because you did not prevent the default submit event from firing in the `onsubmit` callback, so the user is redirected to the form's action immediately when they submit the form. – Terry May 10 '20 at 21:28

1 Answers1

0

Think you will need to set the target attribute of the form to _blank to allow for opening a new context: enter image description here

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form

I would also check chrome/your choice of browser isn't blocking your popup

amprew
  • 253
  • 1
  • 6
  • Opening the window and doing POST request is not the problem, what I wanted is to delay the window.open for 1-3 seconds. Im on Chrome – SecurityQuy May 10 '20 at 21:12
  • if you move the onsubmit callback into a separate method it might be easier to debug why it isn't working. setTimeout will be the correct method for waiting a moment of time before performing an action. – amprew May 10 '20 at 21:17
  • could you possibly share example code which would work? Im still trying to understand this. – SecurityQuy May 10 '20 at 23:30