How to Open Redirect in a New Window

Overview

Would you like to have your form redirect open in a new window or tab? With WPForms you can have your form redirect to a new page upon successful form submission. With a small JavaScript code snippet, you can set this redirect to open in a new window or tab. This tutorial will show you how to add this small snippet to your site to open that redirect in a new window.

Setup

First, you’ll need to set up your form to redirect upon submission. To do this, please review this tutorial.

Open redirect in new window

Next, copy and paste this code to your site. The code snippet shown below will target only the form ID -909.

/**
 * Redirect link in new tab.
 *
 * @link https://wpforms.com/developers/how-to-open-redirect-in-a-new-window/
 *
 */
function wpf_dev_open_redirect_new( ) {
?>
<script type="text/javascript">
    jQuery(function($){
        $("form#wpforms-form-909").attr("target", "_blank");
        });
    </script>
<?php
}
add_action( 'wpforms_wp_footer_end', 'wpf_dev_open_redirect_new', 30 );

You’ll need to make sure you update the code above to add your own form ID.

And that’s it! You’ve successfully set up the redirect on the form to open in a new window/tab. Would you like to change the title that appears inside the tab of the browser window? Take a look at the tutorial on How to Change the Page Title on the Browser Tab.

Action Reference: wpforms_wp_footer_end