Submit HTML form in a new tab
To open a form submission in a new tab, simply use the target="_blank"
attribute in your <form>
tag:
your-action-url is the destination URL for form data. The form's response will then open in a new tab after submission.
Individual button control
In case you want a specific button, not the whole form, to redirect to a new tab upon submission, the HTML5 formtarget
attribute can be helpful:
This approach assigns the "new tab" behavior to a single submit button, providing flexibility in form design.
Preview forms without data persistence
Developing a form? Need a pure preview mechanism? That's where a no-data-persistence button can save the day:
Working similar to browser's incognito mode, this allows previews without the risk of unexpected form submissions. You're being a "data ninja" here, sneaking peeks into the future of your form!
Employing jQuery for dynamic form submission
Sometimes, you need to switch flexibly between opening in the same or a new tab based on certain conditions. jQuery is your friend here:
The code above gives you the ability to toggle the tab destiny dynamically. Perfect for those "Schrodinger's Tab" situations—you don't know where you want to submit until the last moment!
Accidental submission prevention
Accidental clicks are like coffee spills of form submissions. Annoying, but can be prevented:
This differentiates the submit actions, and makes sure the user and form are on the same page (literally and figuratively!)
HTML form security reminders
Remember, an opened page can gain partial access to the page that opened it through the window.opener
object. To prevent potential risks, include rel="noopener noreferrer"
when using target="_blank"
to make sure you don't wake up to find that your data went on an unexpected trip!
Was this article helpful?