form tag has a target attribute, which can be used the control the response after the form submission. target can take one the following values:

  • _blank: The response will be displayed in new tab/window
  • _self: The response will be displayed in same frame. This is the default value
  • _parent: The response will be displayed in parent frame.
  • _top: The response will be displayed in top frame.
  • framename: The response will be displayed in named iframe.

_parent, _top, framename are generally used with iframes. This can be used for our advantage.

For example we can trigger a download (which requires POST request) in same window without redirection.

<iframe name="download" style="display:none"></iframe>
<form method="POST" action="/path/to/download-service" target="download" style="display:none">
  <input type="hidden" name="somefield"  value="somevalue" >
</form>

Upon submission of this form the response will be directed to the iframe and the download will begin.

Leave a Reply