当单击下载按钮时,显示弹出窗口并下载PDF

时间:2019-03-04 14:39:07

标签: php wordpress contact-form-7

我想在我的wordpress网站上下载pdf之前添加弹出窗口。我尝试添加联系表单7事件侦听器,但无法正常工作。有什么想法吗?

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

1 个答案:

答案 0 :(得分:0)

您应该尝试使用WP Post Popup WordPress插件。也许您在WordPress网站中得到了想要的东西