简体   繁体   中英

select iframe and copy all with js

Is there a posibility to select an iframe and copy all to the clipboard? I have the following code to copy to clipboard:

function CopyToClipboard()
{
    CopiedTxt = document.selection.createRange();
    CopiedTxt.execCommand("Copy");
}

What I would like to do is to select all the contents in a iframe and copy them to clipboard with the above method. Is that possible?

No, its not possible if the page loaded in the iframe is not one you control. If you control the page being loaded, then you can select the text and pass it to the parent window. But the script has to run in the context of the page in the iframe. This is called sandboxing.

Imagine that you were a bad guy and made a fake bank page. You could load the real bank page into an iframe and trick the user into logging in. Then you would be able to copy all their personal bank data. The sandbox prevents this.

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