How to redirect a Link to a new tab in contact form 7?

admin2025-01-07  3

I was trying to redirect my contact form 7 to specific pdf link. But I m not sure how to open it in new tab can someone help me up with the same ?

Below is my code...

add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7submit', function( event ) {
if ( '876' == event.detail.contactFormId ) {
    location = '.pdf';
    target = '_blank';
}
}, false );
</script>
<?php
}

target = '_blank'; is not working is there any other option to open in new tab ?

I was trying to redirect my contact form 7 to specific pdf link. But I m not sure how to open it in new tab can someone help me up with the same ?

Below is my code...

add_action( 'wp_footer', 'mycustom_wp_footer' );
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7submit', function( event ) {
if ( '876' == event.detail.contactFormId ) {
    location = 'https://spilledsunshine.com/wp-content/uploads/2020/10/10-Reminders-To-Myself-By-Ishita-Mehta.pdf';
    target = '_blank';
}
}, false );
</script>
<?php
}

target = '_blank'; is not working is there any other option to open in new tab ?

Share Improve this question asked Dec 7, 2020 at 6:38 Mohammed Hussain MerchantMohammed Hussain Merchant 112 bronze badges 1
  • 1 I don't think that's actually setting target=_blank on anything - you're just making a JavaScript variable and not using it anywhere. In any case you probably need to set it on the <form> tag. – Rup Commented Dec 8, 2020 at 17:54
Add a comment  | 

1 Answer 1

Reset to default 0

You got it right,

<a target="_blank" href="https://google.com">Google</a>

The _blank directive opens the link in a New window/tab depending on the browser setting. This is only way to achieve your redirect in a new tab, but is entirely dependent on the user's browser setting over which you have no control.

Anyhow, it's not recommended to open pdf in a new window/tab.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736259250a575.html

最新回复(0)