简体   繁体   English

如何获取表格页面 url?

[英]How to get the form page url?

I want to get the live URL from which an HTML form has been submitted.我想获取已提交 HTML 表单的实时 URL。 Like a hidden input tag using a javascript function, which will send me the URL with the form submission.就像使用 javascript function 的隐藏输入标签一样,它会将 URL 与表单提交一起发送给我。 How can I do that?我怎样才能做到这一点?

If your backend language is PHP, look for $_SERVER['HTTP_REFERER'].如果您的后端语言是 PHP,请查找 $_SERVER['HTTP_REFERER']。 Other backend languages also have similar Referrer global variables.其他后端语言也有类似的 Referrer 全局变量。

You can add submit event to your form , it will be executed shortly before submit action.您可以在form中添加submit事件,它将在提交操作之前不久执行。 And set value of hidden field.并设置隐藏字段的值。

 let myForm = document.getElementById('form'); myForm.addEventListener('submit', function(){ let myForm = document.getElementById('url').value = location.href; })
 <html> <body> <form id="form" action="" method="post"> <input type="hidden" name="html" id="url"> <input type="submit"> </form> </body> <html>

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

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