问题
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