標籤:jquery UI libs idt man init 支援 pod ipo
補充上篇部落格 中出現的ios複製停用問題需要組合使用
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title></head><body> <span id="data">複製我到剪貼簿</span> <button class="button" type="button" id="button">點擊複製</button> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script> <script> $("#button").click(function () { if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { //ios var copyDOM = document.querySelector(‘#data‘); //要複製文字的節點 var range = document.createRange(); // 選中需要複製的節點 range.selectNode(copyDOM); // 執行選中元素 window.getSelection().addRange(range); // 執行 copy 操作 var successful = document.execCommand(‘copy‘); try { var msg = successful ? ‘successful‘ : ‘unsuccessful‘; console.log(‘copy is‘ + msg); } catch (err) { console.log(‘Oops, unable to copy‘); } // 移除選中的元素 window.getSelection().removeAllRanges(); } else { console.log( "android不支援此方式複製") } }); </script></body></html>
ios複製文字到剪下板