Tıkla ve Kopyala Javascript

jQuery(document).ready(function($) {
// If a copy clickable input is clicked
// input value will be highlighted and copied to clipboard
$(‘body’).on(‘click’, ‘input.js-click-to-copy-input’, function(e) {
copy_input( this );
});

// If a button to copy an input is clicked
// associated input value will be highlighted and copied to clipboard
$(‘body’).on(‘click’, ‘a.js-click-to-copy-link’, function(e) {
e.preventDefault();
var copy_id = $(this).data(‘copy-id’);
copy_input( $(‘#’+copy_id) );

});

// If copy clickable text is clicked
// all text in this element will be highlighted and copied to clipboard
$(‘body’).on(‘click’, ‘.js-click-to-copy-text’, function(e) {
var range = document.createRange();
var sel = window.getSelection();
range.setStartBefore(this.firstChild);
range.setEndAfter(this.lastChild);
sel.removeAllRanges();
sel.addRange(range);
try {
var successful = document.execCommand(‘copy’);
} catch(err) {
console.error(‘Unable to copy’);
}
});

// copy function
function copy_input( $input ) {
$input.focus();
$input.select();
try {
var successful = document.execCommand(‘copy’);
} catch(err) {
console.error(‘Unable to copy’);
}
}
});

// Plain JavaScript
// <textarea name=”email-details” id=”message-textarea” rows=”15″ style=”width: 100%”>
// <a href=”#” class=”button secondary” id=”js-copy-message”>Copy Message</a>
<script>
var copy = document.getElementById(‘js-copy-message’);
copy.onclick = function() {
var copyTextarea = document.querySelector(‘#message-textarea’);
copyTextarea.select();
try {
var successful = document.execCommand(‘copy’);
var msg = successful ? ‘successful’ : ‘unsuccessful’;
console.log(‘Copying text command was ‘ + msg);
} catch (err) {
console.log(‘Oops, unable to copy’);
}
return false;
};
</script>

 

<!– input value will be highlighted and copied to clipboard if clicked in –>
<input id=”clickable-input” class=”js-click-to-copy-input” type=”text” value=”Text to copy” readonly><br>

<!– associated input value will be highlighted and copied to clipboard if this link is clicked –>
<a href=”#” data-copy-id=”clickable-input” class=”js-click-to-copy-link button”>Copy</a><br>

<!– all text in this element will be highlighted and copied to clipboard if clicked –>
<pre class=”js-click-to-copy-text”>Text to copy</pre>

<!– This will work without an external JavaScript file –>
<input value=”Text to copy” >

 

Recent Posts

Instagram Uygulaması iPad’e Geliyor

Instagram, iPad kullanıcılarının uzun süredir beklediği uygulama için çalışmalara resmen başladı. Meta bünyesindeki ekiplerin uygulamayı…

% gün önce

WhatsApp, Hesap Silmeden Çıkış Yapma Özelliğini Test Ediyor

WhatsApp, kullanıcıların hesaplarını silmeye gerek kalmadan uygulamadan çıkış yapabilmelerini sağlayacak yeni bir özelliği test ediyor.…

% gün önce

X’in Yapay Zekası Grok, Telegram’a Geliyor

Elon Musk’ın yapay zeka şirketi xAI, geliştirdiği sohbet botu Grok’u Telegram’a entegre ederek kullanıcıların yapay…

% gün önce

WhatsApp’ın iPad Uygulaması Yayınlandı

WhatsApp, iPad kullanıcıları için resmi uygulamasını yayınladı. Artık iPad kullanıcıları, App Store üzerinden WhatsApp’ı indirerek…

% gün önce

Google I/O 2025: Yapay Zeka, Yeni Pixel ve Android 15 ile Geleceğe Yön Veren Yenilikler

Google, 2025 yılına ait Google I/O etkinliğinde, kullanıcı deneyimlerini daha da geliştirmeyi amaçlayan birkaç önemli…

% gün önce

Google’dan Yeni Yapay Zeka Modeli: Imagen 4

Google, 20 Mayıs 2025 tarihinde düzenlenen Google I/O etkinliğinde yeni yapay zeka görsel üretme modeli…

% gün önce