我有一个iFrame,它的内容在不同的域,我也可以控制。我喜欢将机密数据从父类传递到iFrame。因此,我不想通过查询字符串或URL传递它。我喜欢通过表单隐藏输入字段传递它。如果字段的值是文本,则可以工作。但是,如果我使用AngularJS变量作为字段的值,它就不起作用了。
下面是我的代码。
{{session.user.user_ID}} and {{i18n.domain}} works in this HTML file and writes the correct values to the webpage.
<form id="form_frame" action="http://other.mydomain.com/forIframe.php" method="post" target="output_frame">
<input type="hidden" value="{{session.user.user_ID}}" name="id" />
<input type="hidden" value="{{i18n.domain}}" name="domain" />
</form>
<iframe name="output_frame" width="400" height="400">
</iframe>
<script language="JavaScript" type="text/javascript">
document.getElementById("form_frame").submit(); // automatically submit the form
</script>
我在我的forIframe.php文件中有这个,它是为iFrame写入内容的文件:
echo 'user ID is: '.$_POST['id'];
然而,上面的代码是这样写的:
user ID is: {{session.user.user_ID}}
为什么这个AngularJS变量不能正确解析为输入字段的value属性?如何传递{{session.user. user.}中的值?user_ID}}和{{i18n。domain}}安全到我的PHP文件在我的iFrame?
iFrame中的元素不继承父元素的作用域。最好的办法是使用消息传递,即$broadcast和$on: http://plnkr.co/edit/Osa5MNKiJKzsi7wAUXgM?p=preview