PS:初步發(fā)現(xiàn)是瀏覽器兼容問題,只有IE支持clipboardData,那么問題來了,有沒有更優(yōu)的方法?問題闡述:global.html里有一個(gè)“id=biao1”的iframe,現(xiàn)欲通過js抽取iframe中div標(biāo)簽的文本內(nèi)容并復(fù)制到剪貼板,本例欲采用clipboardData.setData方法并出現(xiàn)如下報(bào)錯(cuò)信息,請(qǐng)大牛指點(diǎn)。報(bào)錯(cuò)信息:zhiliangbaobiao.js:8 Uncaught TypeError: Cannot read property 'setData' of undefinedat copysql1 (zhiliangbaobiao.js:8)at HTMLInputElement.onclick (global.html:172)global.html 主要源碼<iframe id="biao1" src="test00.html" frameborder="0" style="width:100%;height:100%;"></iframe><input class="btn btn-success" onclick="copysql1()" value="點(diǎn)擊復(fù)制代碼" type="button">zhiliangbaobiao 主要源碼var ifr = document.getElementById('biao1');var ifrwin = ifr.window || ifr.contentWindow;var temp = ifrwin.document.getElementsByTagName("div").item(0).innerText;window.clipboardData.setData("text",temp);
兼容主流瀏覽器前提,如何實(shí)現(xiàn)實(shí)現(xiàn)剪貼板功能,用js。
ibeautiful
2018-11-20 17:18:42