Material Box

Material Box

WEB Design & Material Images

JavaScript - Detect text copy operation

JavaScript

A JavaScript code example for detecting text copy operations.


The HTML has a paragraph with class "text" to detect copies from.

<div class="item-container">
	<p id="text">Please copy this text.</p>
	<p id="output">***</p>
</div>

An event triggered on copy is implemented on the target element with addEventListener().

// Implement copy triggered event
document.querySelector('#text').addEventListener('copy', () => {
	output.textContent = 'Copied text.';
});

JavaScript - Detect text copy operation

TitleJavaScript - Detect text copy operation

CategoryJavaScript

Created

Update

AuthorYousuke.U