wmaraci reklam
lidertakipci

JavaScript Karakter Sınırına Göre İşlem

3 Mesajlar 840 Okunma
advertseo
wmaraci reklam

SertacYANIK SertacYANIK Üyeliği Durdurulmuş Banlı Kullanıcı
  • Üyelik 22.03.2015
  • Yaş/Cinsiyet 28 / E
  • Meslek Nothing
  • Konum İstanbul Avrupa
  • Ad Soyad S** Y**
  • Mesajlar 714
  • Beğeniler 21 / 157
  • Ticaret 2, (%100)
Merhabalar, Örnek kod üzerinde metin kopyalandığında kopyalanan metine site adresi otomatik ekleniyor. Bu koda karakter sınırı nasıl getirebilirim?

Yani atıyorum 200 karakterlik bir yazı kopyalanmadığı sürece bu işlem çalışmayacak.

http://jsfiddle.net/jp6nhmxf/

function addLink() {
//Get the selected text and append the extra info
var selection = window.getSelection(),
pagelink = '

Read more at: ' + document.location.href,
copytext = selection + pagelink,
newdiv = document.createElement('div');

//hide the newly created container
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';

//insert the container, fill it with the extended text, and define the new selection
document.body.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);

window.setTimeout(function () {
document.body.removeChild(newdiv);
}, 100);
}

document.addEventListener('copy', addLink);
 

 

wmaraci
reklam

KadirCeyhan KadirCeyhan WM Aracı Kullanıcı
  • Üyelik 23.10.2016
  • Yaş/Cinsiyet 27 / E
  • Meslek Öğrenci
  • Konum Denizli
  • Ad Soyad K** C**
  • Mesajlar 691
  • Beğeniler 0 / 203
  • Ticaret 6, (%100)

function addLink() {
//Get the selected text and append the extra info
var selection = window.getSelection(),
uzunluk = selection.toString().length,
pagelink = '

Read more at: ' + document.location.href,
copytext = selection + pagelink,
newdiv = document.createElement('div');

//hide the newly created container
newdiv.style.position = 'absolute';
newdiv.style.left = '-99999px';

//insert the container, fill it with the extended text, and define the new selection
if (uzunluk >= 200) document.body.appendChild(newdiv);
newdiv.innerHTML = copytext;
selection.selectAllChildren(newdiv);

window.setTimeout(function () {
document.body.removeChild(newdiv);
}, 100);
}

document.addEventListener('copy', addLink);
SertacYANIK

kişi bu mesajı beğendi.

SertacYANIK SertacYANIK Üyeliği Durdurulmuş Banlı Kullanıcı
  • Üyelik 22.03.2015
  • Yaş/Cinsiyet 28 / E
  • Meslek Nothing
  • Konum İstanbul Avrupa
  • Ad Soyad S** Y**
  • Mesajlar 714
  • Beğeniler 21 / 157
  • Ticaret 2, (%100)
KadirCeyhan Teşekkür ederim.
 

 

wmaraci
Konuyu toplam 1 kişi okuyor. (0 kullanıcı ve 1 misafir)
Site Ayarları
  • Tema Seçeneği
  • Site Sesleri
  • Bildirimler
  • Özel Mesaj Al