Home > Web Front-end > JS Tutorial > body text

How to create a native clipboard in navigator.clipboard browser

php中世界最好的语言
Release: 2018-03-19 16:25:00
Original
3183 people have browsed it

This time I will bring you how to create a native clipboard in the navigator.clipboard browser. What are the precautions for creating a native clipboard in the navigator.clipboard browser? Here are Let’s take a look at practical cases. Browser native clipboard navigator.clipboard

Write navigator.clipboard.writeText

navigator.clipboard.writeText('Linr Text to be copied')
  .then(() => {
    console.log('Text copied to clipboard');
  })
  .catch(err => {
    // This can happen if the user denies clipboard permissions:
    console.error('Could not copy text: ', err);
});
Copy after login

Read navigator.clipboard.readText

navigator.clipboard.readText()
  .then(text => {
    console.log('Pasted content: ', text);
  })
  .catch(err => {
    console.error('Failed to read clipboard contents: ', err);
  });
Copy after login
document.addEventListener('paste', event => {
  event.preventDefault();
  navigator.clipboard.getText().then(text => {
    console.log('Pasted text: ', text);
  });
});
Copy after login

Believe it or not After reading the case in this article, you have mastered the method. For more exciting information, please pay attention to other related articles on the PHP Chinese website!

Recommended reading:

Request cross-domain solution CORS


##react-native flatlist pull-up loading onEndReached triggers frequently Solve the problem


How to use the Dom attribute

The above is the detailed content of How to create a native clipboard in navigator.clipboard browser. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!