Reputation: 5158
on my page I have an iframe which is loading an html form from a different domain. Now I need to manipulate this form via jquery but as because the domains are different, it seems jquery can't access the contents of the iframe (eror: Permission denied for <http://localhost> to get property HTMLDocument.nodeType
). Any ideas?
Upvotes: 0
Views: 2701
Reputation: 124
You can't do this for security reasons, with modern browsers maybe you can use postMessage for this purpose.
More info:
http://softwareas.com/cross-domain-communication-with-iframes
http://benalman.com/code/test/js-jquery-postmessage/
https://developer.mozilla.org/en/DOM/window.postMessage
Upvotes: 1
Reputation: 449783
You can't do this for security reasons. If this were possible, you could e.g. load a user's online banking interface into the iframe, and do things with it.
You will need to use a server-side script that fetches the HTML and serves it to you in a local context. However, be prepared that many things (like relative URLs) are going to break that way.
If you can control the remote site, there might be a way in newer browsers by setting cross-domain access control headers, I don't know. There also is a new technology called CORS but it seems like this is limited to Ajax.
Upvotes: 1