Possible Duplicate:
How to change style of iframe content cross-domain?
Hi everybody.
Is it possible to change an iframe content if it comes from another site? e.g.
<html>
<head></head>
<body>
<iframe src="http://www.go开发者_开发问答ogle.com"></iframe>
</body>
</html>
Thanks.
Simple answer... no. If your referring to dom manipulation of the document loaded in the iframe.
For a longer answer see http://en.wikipedia.org/wiki/Cross-site_scripting
No it is not possible to edit the contents of an iframe from another domain, otherwise this would be a huge security risk.
This is called Cross Site Scripting, which is always a no-no.
Not what you're going to want to hear but... No... You can't even use JavaScript to alter the contents of the iFrame if you do not have control over the domain and can access the files in your example Google.com.
No;
But you can get around this, sort of, if you pipe the content through your own domain.
So if you have a script at mydomain/fakegoogle that does something along the lines of
echo file_get_contents("google.com").
Then on your iframe, point the source at mydomain/fakegoogle. Not the most efficient, but it works if all you need is the content from that cross domain request.
No, but you can communicate if both pages agree to do so, such as with window.postMessage
. This is a security feature for your protection. Here's a link to a jquery plugin window.postMessage wrapper with location.hash fallback support.
精彩评论