Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重定向联系人表单7后生成唯一url_Javascript_Php_Wordpress - Fatal编程技术网

Javascript 重定向联系人表单7后生成唯一url

Javascript 重定向联系人表单7后生成唯一url,javascript,php,wordpress,Javascript,Php,Wordpress,我使用这个代码 <script type="text/javascript"> document.addEventListener( 'wpcf7mailsent', function( event ) { location = 'https://www.example.com/thank-you/'; }, false ); </script> 谢谢@pagalprogrammerhttps://www.example.com/thank-you/fds

我使用这个代码

<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
       location = 'https://www.example.com/thank-you/';
}, false );
</script>
谢谢@pagalprogrammer

https://www.example.com/thank-you/fdsffdfggfh 将以服务器路由结束。因此,您需要配置服务器nginx等,以将这些请求重定向到https://www.example.com/thank-you.

另一种方法: 您可以使用查询参数-https://www.example.com/thank-you?YOUR_KEY=fdsffdfggfh
或散列https://www.example.com/thank-youfdsffdfggfh

您可以通过在目标页面上添加以下代码片段轻松做到这一点:

function random_string(length) {
   var res = '';
   var chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
   var charLen = chars.length;
   for ( var i = 0; i < length; i++ ) {
      res += chars.charAt(Math.floor(Math.random() * charLen));
   }
   return "/"+res;
}
window.history.pushState("", "", window.location.href+random_string(10));

你也可以把一些其他的随机字符串函数。这段代码利用了历史API

我对你的理解有点不明白。我需要的网址显示https://www.example.com/thank-you/fdsffdfggfh 内容就是这个页面https://www.example.com/thank-you/that 页面已经有了自己的urlhttps://www.example.com/thank-you/ 它的页面保存在wp管理仪表板的页面部分。你需要给它分配另一个,它和你的例子相符吗?我只是不知道如何把它放在一起我想去看,但显示这个内容。。。你的代码,我把它的发送我的电子邮件,并没有重定向我,这个代码改变网址是的,但没有重新检测我看到。你能告诉我你在用最后一部分做什么吗?或者你到底想做什么?我先试试你的密码。这是工作,谢谢,看到我的问题,我更新它。多谢各位
function random_string(length) {
   var res = '';
   var chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
   var charLen = chars.length;
   for ( var i = 0; i < length; i++ ) {
      res += chars.charAt(Math.floor(Math.random() * charLen));
   }
   return "/"+res;
}
window.history.pushState("", "", window.location.href+random_string(10));