0

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 ?

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
    Dec 8, 2020 at 17:54

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.