javascript - Compatible with mainstream browsers, how to implement the clipboard function using js.
为情所困
为情所困 2017-06-24 09:44:00
0
2
774

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

<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 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); 
为情所困
为情所困

reply all(2)
过去多啦不再A梦

Use flash or let users copy manually.

仅有的幸福

You can use the clipboard.js library (pay attention to browser compatibility) or directly use Flash.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!