zoukankan      html  css  js  c++  java
  • clipboardData.setData与js常用复制到剪贴板脚本

    利用clipboardData.setData访问剪切板属性,
    只IE支持此方法,
    所以先写一段浏览器判断,针对IE使用剪切板脚本,
    非IE提示手动复制

    js:

     1 <script type="text/javascript">
     2 //留用判断浏览器
     3 //    var Sys = {};
     4 //    var ua = navigator.userAgent.toLowerCase();
     5 //    var s;
     6 //    (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
     7 //    (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
     8 //    (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
     9 //    (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
    10 //    (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
    11 
    12 function Id(id) {    return document.getElementById(id);}
    13 function clipLink() {
    14 var text = Id('txt_link').value;
    15 Id('btn_link').onclick=function () {
    16 if(document.all){
    17 window.clipboardData.setData("text",text);
    18 //alert(text);
    19 }else{
    20 alert('对不起你的浏览器不支持此复制功能!请使用CTRL+C或鼠标右键复制');
    21 Id('txt_link').focus();
    22 Id('txt_link').select();
    23 };
    24 }
    25 }
    26 
    27 window.onload =function () {
    28 clipLink();
    29 }
    30 </script>

    HTML:

    1 <input id="txt_link" type="text" value="http://www.baidu.com/bujichong"><button id="btn_link">复制</button> 
  • 相关阅读:
    C语言第0次作业
    C语言博客作业02循环结构
    C语言博客作业04数组
    C语言博客作业03函数
    #C博客作业01分支、顺序结构
    函数
    operation on i may be undefined
    #关于C语言的顺序结构
    关于代码习惯
    VS2019调试的一系列待理解解决问题
  • 原文地址:https://www.cnblogs.com/lpfuture/p/2942632.html
Copyright © 2011-2022 走看看