本段代码摘自微软docs网站上,目前需要解决在IE浏览器中触发copy事件的方法,也可以直接调用jquery。

<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
</head>
<body>
<input id="userToken" type="text" value="asdfasgihaoihhliuhlihfwie" />
<button onclick="copyText();">Copy Text</button>
<script type="text/javascript">
var copyToClipboard = function (text, langClass) {
//text = $.trim(text); if (langClass === 'lang-powershell') {
text = text.replace(/\bPS C:\\>\s?/gi, '');
} if (window.clipboardData && window.clipboardData.setData) {
$(window).trigger("copy", text);
return window.clipboardData.setData("Text", text);
} else if (document.queryCommandSupported && document.queryCommandSupported("copy")) {
var txt = document.createElement("textarea");
txt.textContent = text;
txt.style.position = "fixed";
document.body.appendChild(txt);
txt.select();
try {
return document.execCommand("copy");
} catch (ex) {
return false;
} finally {
document.body.removeChild(txt);
}
}
} var copyText = function () {
var tokenEl = document.getElementById("userToken");
if (tokenEl) {
var success = copyToClipboard(tokenEl.value, "");
if (success) {
alert("copyed");
}
}
} </script>
</body>
</html>

javascript copy text to clipboard的更多相关文章

  1. JavaScript type="text/template"的用法

    JavaScript type="text/template"相当于定义一个模板,如果没有使用html()方法的话,是显示不出来的,我们直接看例子(我是在tp框架的里面写的) &l ...

  2. JS 点击复制Copy插件--Zero Clipboard

    写博客就是一周工作中遇到哪些问题,一个优点就是能够进行一个总结,另外一个优点就是下次遇到相同的问题即使那你记不住,也能够翻看你的博客攻克了.相同也能够帮到别人遇到与你一样问题的人.或者别人有比你更好的 ...

  3. 兼容Android 和 ios JavaScript copy paste

    <!DOCTYPE html> <html> <head> <title>关于我们Frame</title> <meta charse ...

  4. pdf can't copy text 无法复制文字

    有些 pdf 是通过图片弄出来的,或者被 protect 了. 我们会无法 copy 里面的字. 这个时候可以用 OCR (Optical character recognition) 就是从图片中识 ...

  5. [Javascript] Classify text into categories with machine learning in Natural

    In this lesson, we will learn how to train a Naive Bayes classifier or a Logistic Regression classif ...

  6. 关于Javascript中的复制

    在做项目时有一个需求,是需要复制内容到剪切板,因为有众多浏览器,所以要兼容性很重要 1.最简单的copy,只能在IE下使用 使用clipboardData方法 <script type=&quo ...

  7. 使用clipboard.js复制页面内容到剪切板

    最近在做一个的智能客服Web端浏览器应用,其中有一项需求是客户在获取系统返回的 答案后点击“复制答案”按钮将答案复制到系统剪切板.本以为这是一个小case,但是发现如果 要对各种主流浏览器都有良好的兼 ...

  8. clipboard JS(剪切板)的使用

    引入js(根据路径需要修改url) <script src="lib/clipboard/clipboard.min.js" type="text/javascri ...

  9. guake默认快捷键

    toggle guake visibility   切换guake可见 :F12 toggle fullscreen   切换全屏幕 :F11 quit   退出 :Shift+Ctrl+Q new ...

随机推荐

  1. shared_ptr & unique_ptr & weak_ptr (C++11)

    c++11标准废除乐auto_ptr, C++ 标准库智能指针 使用这些智能指针作为将指针封装为纯旧 C++ 对象 (POCO) 的首选项. unique_ptr 只允许基础指针的一个所有者. 除非你 ...

  2. 用Tensorflow实现多层神经网络

    用Tensorflow实现多层神经网络 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 Tensorflow机器学习实战指南 源代码请点击下方链接欢迎加星 ReLU激活函数/L1范数 ...

  3. OpenCV---圆检测

    推文:Opencv2.4.9源码分析——HoughCircles 霍夫圆检测 加载一幅图像并对其模糊化以降噪 对模糊化后的图像执行霍夫圆变换 . 在窗体中显示检测到的圆. def detect_cir ...

  4. Ajax笔记-加强版

    AJAX :   Asynchronous JavaScript and XML 异步JavaScript和XML   用javascript异步形式去操作xml 进行数据交互   节省用户操作,时间 ...

  5. Android Studio 更新失败的解决办法

    编辑$ANDROID_STUDIO_HOME/bin/ 下的 studio.exe.vmoptions(如果系统用的Ubuntu,文件应该是studio.vmoptions或者如果是64位系统,应该是 ...

  6. 超酷动态图片展示墙JS特效制作方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. CSS浏览器兼容问题集-第三部分

    FF与IE 1. Div居中问题 div设置 margin-left, margin-right 为 auto 时已经居中,IE 不行,IE需要设定body居中,首先在父级元素定义text-algin ...

  8. 【CodeForces】889 C. Maximum Element 排列组合+动态规划

    [题目]C. Maximum Element [题意]给定n和k,定义一个排列是好的当且仅当存在一个位置i,满足对于所有的j=[1,i-1]&&[i+1,i+k]有a[i]>a[ ...

  9. oozie与sqoop的简单案例

    1:拷贝模板 2:拷贝hive用的jar包 方式一: 3:编辑job.properties # # Licensed to the Apache Software Foundation (ASF) u ...

  10. spring mvc convention over configuration 之 RequestToViewNameTranslator

    1. RequestToViewNameTranslator简介 在springmvc中很多地方都是约定优于配置的,比如这种写法: @Controller public class IndexActi ...