How to capture clicks from iframe on another domain?
I know this has cross site scripting limitations however I was wondering if there is a way to do this...
I have a customer who uses a 3rd party website to present surveys to users. The survey site does provide iframe code to include on your si开发者_StackOverflow社区te so you can present the survey to your users from your own site. The customer wants to capture some data when the user clicks the submit button within the iframe. I don't need access to any form fields within the survey I just need to some how define an additional custom event in javascript that gets fired when the submit button is clicked in the iframe. Is this possible? How?
Thanks!
There is no way to do this due to the cross site scripting. If you had access to both the iframe content and the outer frame then you could have used events to communicate between the two. But of course you have no control over the iframe content.
If you had access then you could have post a message to get access to the events. Here is a plugin. http://benalman.com/projects/jquery-postmessage-plugin/
No. You cannot reach the DOM in the IFrame at all.
The short answer is: no. Not unless both scripts are on the same domain, for as the reason you identified: security reasons.
See http://softwareas.com/cross-domain-communication-with-iframes.
精彩评论