[英]How to encrypt the formdata message that is sent with the submit action
我有这段代码将属性“onclick”设置为所有提交按钮以调用某个函数。 用户脚本将在社交网站 (Facebook) 上运行并加密用户发送的消息。 所以我想在点击事件上暂停默认操作,访问它以某种方式发送的消息(我猜是 formData ),在文本消息上运行加密功能,并在发送加密的消息的情况下继续提交操作。 所以这里是脚本:
$('textarea', window.content.document)
.closest('form')
.find('input[type=submit]')
.attr("onclick","dont();");
function dont(){
//access formData sent with the submit action and encrypt the message
};
看起来您可能错过了退货。 在 onclick 属性之前没有返回的函数不会阻止动作的发生。
$('textarea', window.content.document)
.closest('form')
.find('input[type=submit]')
.attr("onclick","return dont();");
function dont(){
//access formData sent with the submit action and encrypt the message
//be sure to return true or false depending on if you want the action submitted
};
您可以直接定义调用函数来收集和加密表单本身上的数据,而不是在提交按钮上放置 onclick 函数,如下所示
<form name="sampleForm" method="post" onsubmit="return dont()" enctype="multipart/form-data" action="someurl">
function dont()
{
//code to access the form data and encrypt
if(error)
return false; //Stops the submission of the form
else
return true;
}
否则
只需有一个按钮(输入类型=按钮)而不是提交(输入类型=提交)并定义如下所示的 onclick 函数
<input type="button" value="submit" onclick="dont()" />
function dont()
{
//code to access the form data and encrypt
if(error)
alert("Failed") //Stops the submission of the form
else
document.forms[0].submit();
}
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.