我有一個內容位於不同域的iFrame,我也控制它。我喜歡將來自父級的機密數據傳遞給iFrame。因此,我不想通過查詢字符串或URL傳遞它。我喜歡通過窗體隱藏的輸入字段來傳遞它。如果這些字段的值是文本,它將起作用。但是,如果我使用AngularJS變量作爲字段的值,則不起作用。通過表單輸入字段傳遞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變量不能正確解析輸入字段的值屬性?如何將{{session.user.user_ID}}和{{i18n.domain}}中的值安全地傳遞給我的iFrame中的PHP文件?
將使用ngView可以接受你的情況?使用ngView可以將模板指定爲外部HTML頁面,在AngularJS應用中可以很好地播放:http://docs.angularjs.org/api/ng.directive:ng視圖 –
@DavidRiccitelli使用ng-view指向other.mydomain.com/ forIframe.php,我在angular.js中得到了第5601行的「RangeError:Maximum call stack size exceeded」。用ng-include,什麼也沒有出現。用ng-include指向www.mydomain.com上的一個文件,然後我仍然遇到和以前一樣的問題:「{{session.user.user_ID}}」被傳遞給PHP文件,而不是session.user的值。用戶名。謝謝,我歡迎任何其他建議。 – Curt