我有一个iFrame,在不同的域上有内容,我也控制 . 我想将机密数据从父级传递到iFrame . 因此,我不想通过查询字符串或URL传递它 . 我想通过Form隐藏输入字段传递它 . 如果字段的值是文本,则它可以工作 . 但是,如果我使用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属性?如何将{}和{}中的值安全地传递到我的iFrame中的PHP文件中?
1 回答
iFrame中的元素不会继承父级的范围 . 你最好的选择是使用消息,即$ broadcast和$ on:http://plnkr.co/edit/Osa5MNKiJKzsi7wAUXgM?p=preview