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 ?
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.