PS: Preliminary discovery is that it is a browser compatibility issue. Only IE supports clipboardData. So the question is, is there a better method?
Problem description:
global.html There is an iframe with "id=biao1". Now I want to extract the text content of the p tag in the iframe through js and copy it to the clipboard. In this example, I want to use the clipboardData.setData method and If the following error message appears, please give me some advice.
Error message:
zhiliangbaobiao.js:8 Uncaught TypeError: Cannot read property 'setData' of undefined at copysql1 (zhiliangbaobiao.js:8) at HTMLInputElement.onclick (global.html:172)
global.html Main source code
zhiliangbaobiao main source code
var ifr = document.getElementById('biao1'); var ifrwin = ifr.window || ifr.contentWindow; var temp = ifrwin.document.getElementsByTagName("p").item(0).innerText; window.clipboardData.setData("text",temp);
Use flash or let users copy manually.
You can use the clipboard.js library (pay attention to browser compatibility) or directly use Flash.