Javascript重定向到其他页面不起作用

时间:2019-05-28 13:58:52

标签: javascript wordpress

我正在使用联系表单7插件的WordPress网站上工作。现在,我要重定向页面以感谢您的页面,并使用URL附加表单ID。但是每次它重定向到主页。正在使用wpcf7mailsent DOM事件。

我搜索了几个小时。我使用了以下重定向方法

window.location("/thankyou?submission="+formID);
document.location = 'https://example.com/thankyou'+formID;
document.location.href = '/thankyou?submission='+formID;
window.location.assign('https://example.com/thankyou'+formID);
window.location.replace('https://example.com/thankyou'+formID);
window.location.replace('https://example.com/thankyou'+formID);
jQuery(location).attr('href','example.com/thankyou'+formID);

这是我的代码

var nr_wpcf7Elm = document.querySelector( '.wpcf7' );

nr_wpcf7Elm.addEventListener( 'wpcf7mailsent', function( event ) {
    var inputs = event.detail.inputs;
    var formID = event.detail.contactFormId;
    window.location.href = '/thankyou?submission='+formID;
}, false );

我需要将用户重定向到“谢谢”页面,并且我希望URL具有表单ID。

1 个答案:

答案 0 :(得分:0)

尝试使用wpcf7submit事件。

var nr_wpcf7Elm = document.querySelector( '.wpcf7' );

nr_wpcf7Elm.addEventListener( 'wpcf7mailsubmit', function( event ) {
    var inputs = event.detail.inputs;
    var formID = event.detail.contactFormId;
    window.location.href = '/thankyou?submission='+formID;
}, false );
相关问题