【发布时间】:2019-05-28 13:58:51
【问题描述】:
我正在使用联系表格 7 插件的 WordPress 网站工作。现在我想将页面重定向到感谢页面并在表单 ID 后面附加 URL。但每次它重定向到主页。我正在使用 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 );
我需要将用户重定向到感谢页面,并且我想要带有表单 ID 的 URL。
【问题讨论】:
-
这个问题很可能是因为formID未定义。
-
formID 在这里定义 var formID = event.detail.contactFormId;它具有价值
-
已声明并设置,但很可能未定义。请 console.log() 它并告诉我们结果。
-
控制台显示值
-
先把它全部弄出来:var linkText = '/thankyou?submission='+formID; console.log(linkText);
标签: javascript wordpress