简体   繁体   English

将表单数据发布到iframe中的另一个表单

[英]POST form data to another form inside an iframe

So i am running a JX Browser which allows content to be shown in an iframe . 因此,我正在运行一个JX Browser ,该JX Browser允许在iframe显示内容。 When someone logs into my ticketing software i want to post their username and password to another form in an iframe . 当有人登录我的票务软件时,我想将其username and passwordiframe另一种form中。

Basically the iframe contains a page in which i want them to be automatically logged in to. 基本上, iframe包含一个页面,我希望它们可以在其中自动登录。 The login credentials for the ticketing software and the page are the same all i want to do is pass that credential to an iframe in which there is username and password field. 票务软件​​和页面的登录凭据与我要执行的操作相同,就是将凭据传递给iframe ,其中包含用户名和密码字段。

Like in jquery you can get .val of the what every is submitted and just send it to another form field.. i want to do that.. 像在jquery中一样,您可以获取提交的.val文件,然后将其发送到另一个表单字段中。

What is the best practice? 最佳做法是什么?

You can set target attribute on a form to point it to an <iframe> by name. 您可以在表单上设置target属性,以按名称将其指向<iframe>

For example: 例如:

<form action="process_login_url" method="post" target="iframelogin" id="loginform">
  <input name="login" type="hidden" value="login" />
  <input name="password" type="hidden" value="p4ssw0rd" />
</form>
<iframe name="iframelogin">
<script>
// automatically post the form
document.getElementById('loginform').submit()
</script>

You need to pre-populate the hidden fields with user login and password, then the form is automatically sent to the iframe. 您需要使用用户登录名和密码预先填充隐藏字段,然后表格会自动发送到iframe。 action on your form has to be the other login processing url, not the login form itself (if these are separate). action的形式有可能成为其他登录处理的URL,而不是登录表单本身(如果它们是独立的)。 So basically the action attribute of the external form. 所以基本上是外部形式的action属性。 Names of the input fields also have to match the target form's names. 输入字段的名称还必须与目标表单的名称匹配。

Example: http://jsfiddle.net/297suggf/2/ - note the iframe has no src attribute, it loads the url from action on the form with the POST data passed with the request. 示例: http : //jsfiddle.net/297suggf/2/-请注意, iframe没有src属性,它使用与请求一起传递的POST数据加载表单上的action的url。 (It's some random website that allows testing POSTs). (这是一个允许测试POST的随机网站)。

I don't think it's a great idea, and it may not work if there's a protection on the receiving end (like a CSRF token), but youu may give it a shot if it's a last resort type situation 我认为这不是一个好主意,并且如果在接收端有保护(例如CSRF令牌),则可能不起作用,但是如果是万不得已的情况,您可以尝试一下

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

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