


Simple implementation of js compatible with major browsers to copy content to the clipboard_jquery
Because website articles need to provide several buttons, click to copy the article content to the clipboard.
I searched a lot of content on the Internet and found that it is quite messy. Here I will sort it out and share it with everyone
The rendering is as follows:
I used window.clipboardData.setData before, which only supported IE and Firefox. 360 Browser, Sogou and other browsers were all in tears. Therefore, I studied ZeroClipboard and tried to use js code to write it.
Quote three things before use (no upload attachments are provided, so the download address is not provided here. It is very common. You can find a girl by yourself):
jquery-1.4.1.min.js
ZeroClipboard.js
ZeroClipboard.swf
The following is the simplest implementation, please explain it.
Principle
Place an invisible Adobe Flash movie element on a DOM element. When the user clicks on the DOM element, he actually clicks on the invisible Adobe Flash movie element, and the Flash code copies the content to the clipboard.
Note: If you use js to simulate a click event on the flash, you cannot copy the content to the clipboard. The reason is security limitations of browsers and flash.
The a tag is a button. You can replace it with an image, etc., but the ID must be consistent with clip.glue("copy_text"); below.
clip.setText(AddContent document.getElementById("id_div").innerText AddContent); The di_div in this sentence is the ID of the Div to be copied. This ID can be the ID of other tags. Just write the ID of whatever you want to copy.
Copy the rest as they are. What you need to change are the top two lines. The first line is the tag that needs to be copied. Generally, it already exists on your web page. Just set an ID for him. Then the first line can be deleted. You can use the second line as you wish. You can use a hyperlink or a picture, as long as the ID is the same as the one below.
For the three files prepared in advance, please upload them to the path shown in the code. This is said to only work on the server. I directly uploaded it to the server for testing
This is the most simplified code. The mess on the Internet is really unbearable to look at, so I will share it with everyone as soon as I make it. If you have questions about this article, you can leave a message on the blog.
The following is the implemented code:
<div id="id_div">文本内容</div><br><a href='#' id="copy_text" title="以纯文本形式复制">复制文章纯文本内容</a><br> <script type="text/javascript" src="/js/global/jquery-1.4.1.min.js"></script> <script type="text/javascript" src="/js/global/ZeroClipboard.js"></script> <script type="text/javascript"> var clip = null; ZeroClipboard.setMoviePath("/js/global/ZeroClipboard.swf"); $(document).ready(function(){ var AddContent = "\r\n本原创文章来源:C++技术网,阅读更多原创精品文章,欢迎访问C++技术网。 \n"; clip = new ZeroClipboard.Client(); clip.setHandCursor(true); clip.setText(AddContent+ document.getElementById("id_div").innerText + AddContent); clip.glue("copy_text"); clip.addEventListener("complete", function(){ alert("文章纯文本内容已经复制到剪切板!"); }); }); </script>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Article discusses creating, publishing, and maintaining JavaScript libraries, focusing on planning, development, testing, documentation, and promotion strategies.

The article discusses strategies for optimizing JavaScript performance in browsers, focusing on reducing execution time and minimizing impact on page load speed.

Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

The article discusses effective JavaScript debugging using browser developer tools, focusing on setting breakpoints, using the console, and analyzing performance.

The article explains how to use source maps to debug minified JavaScript by mapping it back to the original code. It discusses enabling source maps, setting breakpoints, and using tools like Chrome DevTools and Webpack.

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

This tutorial will explain how to create pie, ring, and bubble charts using Chart.js. Previously, we have learned four chart types of Chart.js: line chart and bar chart (tutorial 2), as well as radar chart and polar region chart (tutorial 3). Create pie and ring charts Pie charts and ring charts are ideal for showing the proportions of a whole that is divided into different parts. For example, a pie chart can be used to show the percentage of male lions, female lions and young lions in a safari, or the percentage of votes that different candidates receive in the election. Pie charts are only suitable for comparing single parameters or datasets. It should be noted that the pie chart cannot draw entities with zero value because the angle of the fan in the pie chart depends on the numerical size of the data point. This means any entity with zero proportion

Once you have mastered the entry-level TypeScript tutorial, you should be able to write your own code in an IDE that supports TypeScript and compile it into JavaScript. This tutorial will dive into various data types in TypeScript. JavaScript has seven data types: Null, Undefined, Boolean, Number, String, Symbol (introduced by ES6) and Object. TypeScript defines more types on this basis, and this tutorial will cover all of them in detail. Null data type Like JavaScript, null in TypeScript
