Write & read from the clipoard

by Comandeer

HTML

<button>Write &amp; read from the clipboard</button>

JavaScript

document.querySelector( 'button' ).addEventListener( 'click', async () => {
	await navigator.clipboard.writeText( 'Hello, world!' );

	const text = await navigator.clipboard.readText();

	console.log( text ); // Hello, world!
} );