I want to add popup before going to download pdf in my wordpress site. I try to add contact form 7 event listener but it's not working. Any idea??
<p class="margin-xs-top20"><?php
if( get_field('download') ): ?>
<button data-toggle="modal" data-target="#myModal" type="file" class="btn btn-default btn-lg btn-primary btn-huge">download publication
<script>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '4265' == event.detail.contactFormId ) { // Sends sumissions on form 4265 to the first thank you page
var pdfLink = '[DOMAIN]/wp/wp-content/uploads/2018/06/file.pdf';
} else if ( '4266' == event.detail.contactFormId ) { // Sends submissions on form 1070 to the second thank you page
var pdfLink = '[DOMAIN]/wp/wp-content/uploads/2018/06/file2.pdf';
}
else {
//do nothing
}
jQuery.get(pdfLink, (data) ->
window.location.href = jQuery(this).attr('href');
)
}, false );
</script>
</script></button>
<?php endif; ?></p>
You should have tried to WP Post Popup WordPress plugin. Maybe you get what you want in your WordPress site