A way to solve the Clipboard mobile phone terminal cannot copy

Source: Internet
Author: User

Recently, I made a small project of cutting graphs.

The main content is the promotion of the page, there will be beautiful pictures and numbers:)

Click on the button, will be copied to the Clipboard, go inside paste search:), lazy people will do a series of complex operations, not optimistic

First, Baidu a bit, fancy Clipboard library, pure JS compatible mobile phone side, good excitement:)

Clibboard GitHub address, use very simple, look at the contents of the demo directory, source to see the side, or do not know how to achieve, ask

The main idea is to automatically copy the text to the Clipboard by clicking on the button.

Select the function in which you can use Ajax to get the number from the server

The program of the official website

1 New Clipboard ('. Btn ', {2     function(trigger) {3         return Trigger.getattribute (' Aria-label '); 4     }5 });

Now, you need to instantiate it by passing a DOM selector, HTML element, or list of HTML elements.

You can choose from three ways to determine where you click to trigger a click.

Use Zepto to get JSON, depending on your business needs

1 //Add get JSON2Zepto (function ($) {3$.getjson (' Account/data.json ', '? Time= ' +NewDate (). GetTime (),function(data) {4Let name =Data.name;5 6document.getElementById ("num"). InnerHTML =name;7 8         varClipboard =NewClipboard ('. btn '), {9Text: () =nameTen         }); One  AClipboard.on (' Success ', (e) = ={Console.log (e) -Alert (' number has been copied, please open, click on the upper right corner + #, select Add friend, paste search ')}); -  theClipboard.on (' Error ', (e) = =Console.log (e)); -});

The effect is as follows:

Found Click, there are pop-up windows, careful observation will find that the body at the bottom of a string of code, hack way, hidden text

The following is a simple HTML, interested students can try their own

1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4   <MetaCharSet= "UTF-8">5   <title>Test</title>6   <Scriptsrc= "Dist/clipboard.min.js"></Script>7   <Scriptsrc= "Dist/zepto.min.js"></Script>8   <Scriptsrc= "Static/js/changeaccount.js"></Script>9   <style>Ten . BG{ One width:100%; A Height:1500px; - Background-color:#ccc; - text-justify:Inter-cluster; the font-size:100px; -     } -   </style> - </Head> + <Body> - <Divclass= "BTN"> +   <Divclass= "BG"> A background at   </Div> -   <PID= "num"></P> - </Div> - </Body> - </HTML>
View Code

Click on the phone without any effect, this big pit tread for a long time to know,

Concrete how to tread embarrassed said, trickery after all still want to suffer,,,

Looked carefully again the demo, found that most are <button class= "BTN" >

Simply follow the official.

<button class= "BG" >
Background
</button>

Alas, the heart is tired, early this is not good, as for why just start not to use button, are design draft of the pot, unexpectedly no button, also want to

can click Copy,

The page has a lot of background images and content, the initial idea is to set the button to full screen, z-index=-1;

Found, red, green area click Invalid, gray area can be copied, at this time convinced that the mobile phone side click is not penetrate, can only get the top layer

Change the idea, put the button on the top layer, no, you can think of something

1 z-index:999; 2 opacity:0;
View Code

Finally, to see the full project, please visit the individual GitHub

A way to solve the Clipboard mobile phone terminal cannot copy

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.