Passing data between frames with Javascript

陌路散爱 提交于 2019-12-01 12:34:52

问题


I've setup a simple example at http://ryanmalin.co.uk/frames/

If you press "add" it will paste the form data from the left frame into the right frame.

When I change the right frames URL to that of another domain Firebug throws an error and it doesn't work. The error shown is:

Error: Permission denied to access property 'document'

Is it possible to copy data from one pre-filled form on my domain to a form on another domain using frames/javascript?

I believe it is an anti-spam measure built into browsers or websites but if possible I need to get around it. To send customer orders through my parcel delivery company I have been copying over each address field one by one between two browser tabs - now that orders are increasing I need to speed this process up, however the courier doesn't yet have a way of sending all of the days order details at once.

I can write the PHP needed to grab the order details for the left frame but don't want to waste time if its impossible to do what Im after.

Many Thanks :)


回答1:


See the "Same Origin Policy" for a description of how inter frame security works. In a nutshell, there is very little communication allowed between frames on a different domain for security reasons. You cannot make any direct Javascript calls between frames on different domains.

HTML5 has a new messaging system that can safely communicate data (not direct JS calls) between cooperating frames in different domains. See here and here for a description of how the HTML5 messaging works.




回答2:


This is not possible. It's a deliberate browser restriction for security.



来源:https://stackoverflow.com/questions/7170582/passing-data-between-frames-with-javascript

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