Clipboard API

Copy and paste using Clipboard API

IntermediateTopic: Browser API
Back

JavaScript Clipboard API Program

This program helps you to learn the fundamental structure and syntax of JavaScript programming.

Try This Code
async function copyToClipboard(text) {
    await navigator.clipboard.writeText(text);
    console.log('Copied to clipboard');
}

async function pasteFromClipboard() {
    const text = await navigator.clipboard.readText();
    console.log('Pasted:', text);
}
Output
Copied to clipboard
Pasted: Hello World

Understanding Clipboard API

Clipboard API enables copy/paste operations.

Note: To write and run JavaScript programs, you need to set up the local environment on your computer. Refer to the complete article Setting up JavaScript Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your JavaScript programs.

Table of Contents