简体   繁体   中英

How to clone actual iFrame contents, not just the iFrame tag contents?

I have an iFrame and have worked out how to clone it using jQuery:

<HTML>
<HEAD>
  <SCRIPT type="text/javascript" src="jquery.js"></SCRIPT>
  <SCRIPT>
    function clone_test() {
      $('#FRAME1').clone().appendTo('#divtag');
    }
  </SCRIPT>
</HEAD>

<DIV id="divtag">
  <iframe id="FRAME1" name="FRAME1" src="http://currencies.typeit.org/" width="360" height="360" frameborder="0"></iframe>
</DIV>

<a href="javascript:clone_test()" target="FRAME1">- CLONE THE iFRAME -</a>

</HTML>

But this is not what I want! My problem is that anything typed in the currency box is not included in the cloning process. It seems only the HTML is cloned, not the actual contents of the iFrame. Is there anyway possible to clone the iFrame including anything typed in the currency box? This only has to work for the Chrome browser as I am making a Chrome extension.

如果Iframe来自其他域,则由于“相同来源策略”,您将无法访问其内容。

I don't think this is possible, your code just duplicates iframe element, which loads external page again, co it's in "default" state. But you cannot access content of iframe.

This cant be done when the url of the iframe and the url of your domain are not the same.

If they are the same you need to clone the document element of the iframe as well and append it to the cloned iframe.

There is a workaround for this though. Due to Same Origin Policy you need to use curl (if you are using php) to "fake" that the content is coming from the same domain. After which, you may be able to get the content of the iframe by using.

$("#frameid").contents().find("body *");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM