How change a iframe content? [duplicate]

强颜欢笑 提交于 2019-12-14 04:08:15

问题


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.google.com"></iframe>
 </body>
</html>

Thanks.


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/5638387/how-change-a-iframe-content

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