/** * [点击复制内容移动端全兼容(专治各种移动端浏览器)] * @author majiang by beijing * @createtime 2018-11-17 * @blog http://www.love85g.com */ ;(function($){var defaults={imgUrl:"",text:"复制成功",copyUrl:"",tipTime:2000,copyId:""};$.extend({copy:function(option){var options=$.extend({},defaults,option);var URL=options.copyUrl==""?window.location.href.split('#')[0]:options.copyUrl;var cId=options.copyId==""?'#copy':options.copyId;var IMG=options.imgUrl==""?"":'';var tipsHtml='
'+IMG+'

'+options.text+'

';var u=navigator.userAgent;var isAndroid=u.indexOf('Android')>-1||u.indexOf('Adr')>-1;var isiOS=!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);var aEle=document.querySelectorAll(cId);if(isAndroid||(!isAndroid&&!isiOS)){$(aEle).each(function(){var index=$(this).attr("id").split("y")[1];$('body').append('');$(this)[0].onclick=function(event){$("#selector"+index).select();document.execCommand("copy",false,null);$("body").append(tipsHtml);setTimeout(function(){$("#share-tips").remove()},options.tipTime)}})}if(isiOS){$(aEle).each(function(){var index=$(this).attr("id").split("y")[1];$('body').append(''+URL+'');this.addEventListener('click',function(){var copyDOM=document.querySelectorAll('#selector'+index);var range=document.createRange();range.selectNode(copyDOM[0]);window.getSelection().removeAllRanges();window.getSelection().addRange(range);document.execCommand('copy');$("body").append(tipsHtml);setTimeout(function(){$("#share-tips").remove()},options.tipTime)},false)})}}})})(jQuery);