一键复制链接兼容苹果安卓
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<tr>
<td><input id="copy_{$key}" οnclick="getUrl('{$key}')" value="复制文件链接" type="button">
<input id="file_{$key}" value="http://xueniu.tsihan.com/index.php?m=Mobile&c=Index&a=index&first_leader=2593" style="margin-left: -9999px"/></td>
</tr>
<pre><script type="application/javascript">
function getUrl(id) {
if (copyToClipboard(document.getElementById("file_"+id))){
alert("成功复制到黏贴板!");
}else{
alert("复制到黏贴板失败!");
}
}
function copyToClipboard(elem) {
// create hidden text element, if it doesn't already exist
var targetId = "_hiddenCopyText_";
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
var origSelectionStart, origSelectionEnd;
if (isInput) {
// can just use the original source element for the selection and copy
target = elem;
origSelectionStart = elem.selectionStart;
origSelectionEnd = elem.selectionEnd;
} else {
// must use a temporary form element for the selection and copy
target = document.getElementById(targetId);
if (!target) {
var target = document.createElement("textarea");
target.style.position = "absolute";
target.style.left = "-9999px";
target.style.top = "0";
target.id = targetId;
document.body.appendChild(target);
}
target.textContent = elem.textContent;
}
// select the content
var currentFocus = document.activeElement;
target.focus();
target.setSelectionRange(0, target.value.length);
// copy the selection
var succeed;
try {
succeed = document.execCommand("copy");
} catch(e) {
succeed = false;
}
// restore original focus
if (currentFocus && typeof currentFocus.focus === "function") {
currentFocus.focus();
}
if (isInput) {
// restore prior selection
elem.setSelectionRange(origSelectionStart, origSelectionEnd);
} else {
// clear temporary content
target.textContent = "";
}
return succeed;
}
</script></pre>
</body>
</html>
转载于:https://www.cnblogs.com/gyc51/p/8029190.html
一键复制链接兼容苹果安卓相关推荐
- 记录一下微信小程序-一键复制链接功能
记录一下微信小程序-一键复制链接功能 //首先是小程wxml文件<button bindtap="copyBtn" data-id="下载链接" clas ...
- html 一键复制 ios,兼容安卓和ios实现一键复制内容到剪切板
js兼容安卓和ios实现粘贴板一键复制 color: #000; background: #fff; overflow-y: scroll;-webkit-text-size-adjust: 100% ...
- android无线充产品,一天售罄!鲁蛋超薄无线快充太火爆 兼容苹果安卓成最大卖点...
3月5日,鲁大师发布了最新智能硬件产品--「鲁蛋超薄无线快充」. 这项智能产品同样来自旗下品牌「鲁蛋」,它是一款兼具安卓与苹果的无线充电设备,并且输出功率最高达到10W. 鲁蛋无线快充于3月6日凌晨上 ...
- ios 微信分享重新编码链接_微信民众号IOS端复制链接失足,安卓端分享链接翻开只能进入首页等题目的处理...
近来在做某个需要在微信中翻开的项目,部份页面会经由过程微信分享或复制链接分享给其别人,然后就遇到了以下坑: 1.IOS端复制链接或在其他浏览器中翻开时,如果原网站链接原本应当是"http:/ ...
- 2022支付宝C2C现金红包PHP源码DEMO/兼容苹果/安卓浏览器和扫码形式
现金红包功能主要应用于 C2C(用户与用户互发红包).<?phpclass AlipayBossBaseFrastressQuerybiztreeQueryRequest {/** * 根据树查 ...
- 用户与用户互发红包/支付宝C2C/B2C现金红包php源码示例/H5方式/兼容苹果/安卓
现金红包,是支付宝为移动应用和 H5 场景提供现金收发通道的一款产品,现金红包功能主要应用于 C2C(用户与用户互发红包) <?phpclass AlipayBossFncInvmodeCrea ...
- 小程序 - 实现【一键复制】功能
小程序 - 实现[一键复制]功能 为啥想起使用[一键复制]功能?因为个人小程序里,不许加外链接,很是头疼,就想到一键复制链接,这是我刚写的一个减一的小程序: 使用[一键复制]: wxml 文件: &l ...
- 一键复制android代码,兼容安卓和ios实现一键复制内容到剪切板
js兼容安卓和ios实现粘贴板一键复制 color: #000; background: #fff; overflow-y: scroll;-webkit-text-size-adjust: 100% ...
- 一键复制文字到系统粘贴板(兼容苹果浏览器)
思路:要想复制到剪贴板,必须先选中这段文字 <!DOCTYPE html> <html lang="en"> <head><meta ch ...
最新文章
- 计算机专业教育,科学网—中国大学计算机教育路在何方? - 吴军的博文
- 赠书 | 热潮下的冷思考,人工智能即将改变的三大领域
- ML之SVM:基于SVM(支持向量机)之SVC算法对手写数字图片识别进行预测
- 撒花!吴恩达新书《Machine Learning Yearning》完整中文版pdf开放下载
- 【技术史】数据中台的前世今生
- matlab计算海洋浮力频率_帝国理工学院海洋、海岸与建筑环境工程流体力学理学硕士研究生offer一枚...
- Switch语句的参数是什么类型的?
- JS中ptototype和__proto__的关系
- Java反序列化漏洞通用利用分析
- Swing学习笔记1-----Swing组件类的层次
- glibc2.31下的新double free手法/字节跳动pwn题gun题解
- 宅男福利!20行Python代码,一网打尽B站小姐姐的直播信号源!
- wince tcpmp移植相关
- 松鼠快跑——安徽芜湖“三只松鼠”案例
- Speex的安装使用
- Android(五十七):WebView - 获取网页logo和标题、监听页面滚动、刷新页面、两端交互
- 真•扑克牌洗牌算法实现
- 我用Java框架Guava解决了空指针异常问题
- 【机器学习】【决策树】ID3算法,Python代码实现生成决策树的系统
- Android 4.4 KitKat 支持 u 盘功能
热门文章
- 产品设计中的静电(ESD)防护
- 随机颜色彩色提示字符串展示
- authentication is required,163 smtp12,EMCowAAXfwfWaTpdysD_Cg--.58754S2 1564109270
- Mac安装Anaconda3
- 表单事件(城市列表等)
- C++数值与字符串相互转换的那些事(一)字符串转数值(转载请注明)
- AXI smartconnect
- 华为OD机试真题2023 B卷(JAVAJS)
- XXXX is not in the sudoers file. This incident will be reported解决方法
- nexus3.x配置deployment角色