clipboard.js

网页上操作剪贴板相关

。_饼干妹妹 提交于 2020-08-19 04:32:36
查了不少资料,都是推荐用clipboard.js库进行复制操作。 看了代码,大概明白是怎么回事了。重点是浏览器上的javascript是没有操作剪贴板的API的,你不能下一个命令让剪贴板复制某个字符串。 但是可以用document.execCommand('命令')函数执行网页上的命令,因此我们可以用javascript控制选择一段文本,然后执行网页上的复制命令, 即document.execCommand('copy')达到复制的目的。 来源: oschina 链接: https://my.oschina.net/u/3223803/blog/4329761

js复制内容到剪切板

為{幸葍}努か 提交于 2020-08-15 03:25:03
注意第一部分的内容不兼容Safari,全兼容的请使用第二部分方法 第一部分 查看demo请点 这里 。 原生js复制指定内容到剪切板,超简单的实现方式, 实现思路如下: 1.创建一个input,把想要复制的内容赋值到input的value上; 2. 把这个input插入到body内; 3.获取这个input,对它执行选中; 4.执行documen的copy事件; 5,删除刚刚插入的input。 代码如下: html: <button id="btn">复制</button> js: // 复制的方法 function copyText(text, callback){ // text: 要复制的内容, callback: 回调 var tag = document.createElement('input' ); tag.setAttribute( 'id', 'cp_hgz_input' ); tag.value = text; document.getElementsByTagName( 'body')[0 ].appendChild(tag); document.getElementById( 'cp_hgz_input' ).select(); document.execCommand( 'copy' ); document.getElementById( 'cp_hgz

博客园Markdown编辑器修改代码配色、添加代码行号

青春壹個敷衍的年華 提交于 2020-08-13 13:03:49
修改Markdown代码框 UPD 2020-03-15 五天前这个 主题 的作者更新了1.2.6版本,新版本中改善了对MD代码框的支持,本教程的部分内容已非必要。 初始效果 前几天换了博客的 主题 ,开始用博客园的md编辑器写博客,然而md编辑器的代码高亮支持有些糟糕。 在新主题下<pre>标签与<code>标签背景颜色不统一,代码没有行号,高亮也没有原编辑器的好看。在网上找的的各种解决方案要不就是太丑要不就是因为博客园版本迭代而跑不起来。于是就开始一顿魔改。 修改配色 去 highligh.js官网 找一个配色下载CSS贴进去即可,下面是我用的 .cnblogs-markdown .hljs { display: block; overflow-x: auto; padding: 0.5em; background: #1E1E1E !important; color: #FFF; white-space: pre; word-break: normal; font-family: "Consolas",sans-serif!important; font-size:14px!important; } .hljs { display: block; overflow-x: auto; padding: 0.5em; background: #1E1E1E; color:

在vue-vant中使用Clipboard

牧云@^-^@ 提交于 2020-08-10 23:49:33
@/mixins/Clipboard.js import { Toast } from 'vant' import Clipboard from 'clipboard' export default { directives: { copy: { inserted(el) { const obj = new Clipboard(el) obj.on('success', () => { Toast('复制成功') }) obj.on('error', () => { Toast('复制失败,请手动选择复制') }) } } } } 在需要的页面中引入 import Clipboard from '@/mixins/Clipboard' export default { mixins: [Clipboard], ... } 在模板中使用 <van-icon v-copy data-clipboard-text="内容" class="iconfont" class-prefix="icon" name="copy"/> 来源: oschina 链接: https://my.oschina.net/u/2266306/blog/4335894

data-clipboard-text is not working while using clipboard.js

自作多情 提交于 2020-07-31 05:21:32
问题 I have a simple structure to test clipboard.js but it's not working. I used in a simple file because it was not working in the project too: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <button class="btn" data-clipboard-text="Just because you can doesn't mean you should — clipboard.js"> Copy to clipboard </button> <script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js"></script> </body> </html> 回答1: you

How to add copy to clipboard functionality in vuejs with prismjs?

百般思念 提交于 2019-12-23 23:25:52
问题 I am displaying Html syntax using vue-prism-component (https://www.npmjs.com/package/vue-prism-component). Now I want to add a button that should copy the code. So far, I have found a library vue-clipboard2 (https://www.npmjs.com/package/vue-clipboard2) in this they are getting text from an input tag. How I would select the syntax of Html generated by vue-prism-component on a click of button. 回答1: Prism has some documentation for implementing such feature https://prismjs.com/plugins/copy-to

Understanding non-functioning Clipboard.js implementation with AJAX

て烟熏妆下的殇ゞ 提交于 2019-12-12 00:45:56
问题 In a simple Flask application I'm building, I have an endpoint/view that features a keyword search query field (and the results of that query, inserted via an AJAX call). When the user clicks Submit button, an AJAX POST request with the keyword is made and the server responds with a series of lists, each of which is a search result that contains an individual multimedia file asset title, description, and mp4 URL link. These little "packets" of multimedia data are iterated through via

How to make KnokoutJS and ClipboardJS work together?

只愿长相守 提交于 2019-12-11 08:51:40
问题 I try to copy to clipboard some information from Knockout foreach: <tbody data-bind="foreach: selections"> <tr> <td> <a href="#" class="copy_btn" data-bind="attr: { 'data-clipboard-text' : name}"><i class="fa fa-copy"></i></a> </td> </tr> </tbody> with ClipboardJS: var btns = document.querySelectorAll('a.copy_btn'); var clipboard = new Clipboard(btns); clipboard.on('success', function (e) { console.log(e); }); clipboard.on('error', function (e) { console.log(e); }); But it's not copying. What

Using document.execCommand('copy') in mobile

本小妞迷上赌 提交于 2019-12-10 13:35:26
问题 Is there a way to copy to mobile clipboard? I've been researching for days but haven't found a good solution. Clipboard.js doesn't seem to work on mobile, giving me an error "no support :(" I'm currently using the following function: function copytext(text) { var textField = document.createElement('textarea'); textField.innerText = text; document.body.appendChild(textField); textField.select(); document.execCommand('copy'); textField.remove(); } Works like a charm on chrome on my desktop. But

Copy URL from browser using clipboard.js

元气小坏坏 提交于 2019-12-06 12:05:37
问题 I am using the Accusoft document viewer. I have a requirement for a button that when clicked will copy to the clipboard the current URL plus a page number querystring parameter. I am using clipboard.js. I know exactly how to get the current URL and how to add a page number parameter to the URL. What I don't know how to do is make clipboard.js copy a variable (such as the generated URL with page number parameter) to the clipboard. Any help on this? 回答1: Clipboard.js creator here ;) You can use