IFrame and Parent window

早过忘川 提交于 2020-02-05 10:48:12

问题


Can an iframe install a cookie or session on the parent page? How do i get value in an iframe to the parent page without using Ajax? I am trying to pass an Id value from the iframe to the parent page and then submit it.


回答1:


From within your iframe, you can reference the parent document using parent.document. If you had an input field in your parent window and wanted to set a value on it without using AJAX, you should simply be able to do the following using JavaScript:

parent.document.getElementById('myInputId').value = 'some value';
parent.document.getElementById('yourFormId').submit();

You can call functions in your parent page as well:

parent.someFunction();

I'm not sure about manipulating a parent's cookie(s) from a child frame, but your post it seems like all you need to do is store and submit a value. You won't be able to do it with just PHP.



来源:https://stackoverflow.com/questions/4461734/iframe-and-parent-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!