I set up a thank you page redirection which is working fine. But I want to open the redirected URL in a new window. How can I do that?
Here is the code -
add_action( 'wp_footer', 'redirect_cf7' );
function redirect_cf7() {
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'https://example.com/thank-you/';
}, false );
</script>
}
Please help me to achieve that without any plugin.
For your reference, here is the official documentation: Contact Form 7 DOM Events
Okay, got it working. Here is the code which solved the issue:
<?php
add_action( 'wp_footer', 'redirect_cf7' );
function redirect_cf7() { ?>
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
_location = 'https://example.com/thank-you/';
window.open(_location, "MsgWindow");
}, false );
</script>
<?php }
Thanks to all of you for your time.