将表单数据提交给iframe的有效方法 [英] Angular way to submit form data to iframe

查看:648
本文介绍了将表单数据提交给iframe的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下所示的html

< form name =aFormshow =trueaction =iframeUrltarget =iFramemethod =post> < input id =input_datatype =textname =input_datavalue =data/> < / form>< iframe id =iFramename =iFramesrc =iframeUrlheight =500width = 400border = 0> < / p>您的浏览器不支持iframe。< / p>< / iframe>

当页面加载时,我已经有了要提交给iframe的数据。我想要做的是让我的角度控制器在页面加载后立即将表单提交给目标iframe。
点击我创建的提交类型输入给了我在iFrame中查找的结果,但我不希望用户必须这样做,或者甚至不希望用户可以看到该表单。
我已经看到了相当多的纯JavaScript解决方案,但它们看起来并不像它们真正与角色做事的方式相吻合。有关最佳做法的任何建议以及如何在角度上做到这一点?我对这个框架很陌生,所以我也很感激。

解决方案,但我发现这样的工作。

  window.iframeLoad = function(){
if(!_this。提交){
document.getElementById('aForm')。submit();
}
_this.submitted = true;
};

然后制作iframe

 >< code>< iframe id =iFramename =iFramesrc =iframeUrlheight =500width =400border = 
< p>您的浏览器不支援iframe。< / p>
< / iframe>

我仍然有兴趣听到关于此解决方案或其他更好解决方案的其他想法。


I have html like below

<form name="aForm" show="true" action="iframeUrl" target="iFrame" method="post">
  <input id="input_data" type="text" name="input_data" value="data" />
  <input id="input" type="submit" value="post">
</form>

<iframe id="iFrame" name="iFrame" src="iframeUrl" height="500" width="400" border=0>
  <p>Your browser does not support iframes.</p>
</iframe>

I already have the data I want to submit to the iframe when the page is loaded. What I want to do is have my angular controller submit the form to the targeted iframe as soon as the page is loaded. Clicking the submit type input I created gives me the result I'm looking for in the iFrame but I do not want the user to have to do that, or even for the form to be visible to the user. I've seen quite a few pure javascript solutions for this but they don't look like they really mesh with the angular way of doing things. Any suggestions of best practices and how to do this in angular? I'm new to the framework so explanations would be appreciated as well.

解决方案

I don't know if this is an ideal solution but I found something like this works.

window.iframeLoad = function(){
            if (! _this.submitted) {
                document.getElementById('aForm').submit();
            }
            _this.submitted = true;
        };

Then make the iframe

<iframe id="iFrame" name="iFrame" src="iframeUrl" height="500" width="400" border=0 onload="iframeLoad()">
  <p>Your browser does not support iframes.</p>
</iframe>

I'd still be interested in hearing other thoughts on this solution or better ones.

这篇关于将表单数据提交给iframe的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆