PS:初步發現是瀏覽器兼容問題,只有IE支持clipboardData,那么問題來了,有沒有更優的方法?問題闡述:global.html里有一個“id=biao1”的iframe,現欲通過js抽取iframe中div標簽的文本內容并復制到剪貼板,本例欲采用clipboardData.setData方法并出現如下報錯信息,請大牛指點。報錯信息: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="點擊復制代碼" 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);
兼容主流瀏覽器前提,如何實現實現剪貼板功能,用js。
ibeautiful
2018-11-20 17:18:42