简体   繁体   English

联系表格 7 感谢您在新 window 上重定向页面

[英]Contact form 7 thank you page redirection on new window

I set up a thank you page redirection which is working fine.我设置了一个感谢页面重定向,它工作正常。 But I want to open the redirected URL in a new window.但我想在新的 window 中打开重定向的 URL。 How can I do that?我怎样才能做到这一点?

Here is the code -这是代码 -

add_action( 'wp_footer', 'redirect_cf7' );

function redirect_cf7() {
    <script>
        document.addEventListener( 'wpcf7mailsent', function( event ) {
            location = 'https://example.com/thank-you/';
        }, false );
    </script>
}

Please help me to achieve that without any plugin.请帮助我在没有任何插件的情况下实现这一目标。

For your reference, here is the official documentation: Contact Form 7 DOM Events供您参考,这里是官方文档: Contact Form 7 DOM Events

Use this may be this will help you out Now the page will open in another window使用这个可能会帮助你现在页面将在另一个 window 中打开

window.open("https://www.google.com");

You can use window.open您可以使用window.open

document.addEventListener( 'wpcf7mailsent', function( event ) {
     document.addEventListener( 'wpcf7mailsent', function( event ) {
        location =   window.open('https://example.com/thank-you/', '_blank' );
    }, false );

This is local snippet prove that all work(oblivius don't work with snippet but you need to run with local server):这是本地片段证明所有工作(oblivius 不适用于片段,但您需要使用本地服务器运行):

 function redirect(){ location = window.open('https://google.com/', '_blank' ); }
 <button onclick="redirect()">redirect</button>

Okay, got it working.好的,开始工作了。 Here is the code which solved the issue:这是解决问题的代码:

<?php
add_action( 'wp_footer', 'redirect_cf7' );

function redirect_cf7() { ?>
    <script>
        document.addEventListener( 'wpcf7mailsent', function( event ) {
            _location = 'https://example.com/thank-you/';
            window.open(_location, "MsgWindow");
        }, false );
    </script>
<?php }

Thanks to all of you for your time.感谢大家的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM