-
Fototrend
JavaScript != Java (A JavaScript nem összekeverendő a Javával, két különböző programozási nyelvről van szó!)
Új hozzászólás Aktív témák
-
btz
addikt
Ezt próbálgattam már. Nálam nem működik (szokás szerint)
Először így próbáltam:
<script type="text/javascript" >
// Create a fake textarea
const textAreaEle = document.createElement('textarea');
// Reset styles
textAreaEle.style.border = '0';
textAreaEle.style.padding = '0';
textAreaEle.style.margin = '0';
// Set the absolute position
// User won't see the element
textAreaEle.style.position = 'absolute';
textAreaEle.style.left = '-9999px';
textAreaEle.style.top = `0px`;
// Set the value
textAreaEle.value = text;
// Append the textarea to body
document.body.appendChild(textAreaEle);
// Focus and select the text
textAreaEle.focus();
textAreaEle.select();
// Execute the "copy" command
try {
document.execCommand('copy');
} catch (err) {
// Unable to copy
} finally {
// Remove the textarea
document.body.removeChild(textAreaEle);
}
</script>Ekkor a textAreaEle.value = text; érték nem volt definiálva így készítettem neki egy változót. var text = "tesztszöveg";
<script type="text/javascript" >
// Create a fake textarea
const textAreaEle = document.createElement('textarea');
// Reset styles
textAreaEle.style.border = '0';
textAreaEle.style.padding = '0';
textAreaEle.style.margin = '0';
// Set the absolute position
// User won't see the element
textAreaEle.style.position = 'absolute';
textAreaEle.style.left = '-9999px';
textAreaEle.style.top = `0px`;
var text = "tesztszöveg";
// Set the value
textAreaEle.value = text;
// Append the textarea to body
document.body.appendChild(textAreaEle);
// Focus and select the text
textAreaEle.focus();
textAreaEle.select();
// Execute the "copy" command
try {
document.execCommand('copy');
} catch (err) {
// Unable to copy
} finally {
// Remove the textarea
document.body.removeChild(textAreaEle);
}
</script>Hiba: Uncaught TypeError: Cannot read property 'appendChild' of null.
Beraktam bodyba a scriptet, utána semmit nem csinált, viszont a hiba megszűnt.
Aztán a document.body részt cseréltem document.getElementById("mainContent").appendChild(textAreaEle);-re. Így már megjelenik a textarea, benne a tesztszöveg felirattal. (A kódból kitöröltem azt a részt ami elrejti a textarea-t).<html>
<body>
<div id="mainContent">
MAIN CONTENT<br />
</div>
<script type="text/javascript" >
// Create a fake textarea
const textAreaEle = document.createElement('textarea');
var text = "tesztszöveg";
// Set the value
textAreaEle.value = text;
// Append the textarea to body
document.getElementById("mainContent").appendChild(textAreaEle);
// Focus and select the text
textAreaEle.focus();
textAreaEle.select();
// Execute the "copy" command
try {
document.execCommand('copy');
} catch (err) {
// Unable to copy
} finally {
// Remove the textarea
//document.body.removeChild(textAreaEle);
}
</script>
</body>
<html>Viszont nem másol semmit a vágólapra.
Új hozzászólás Aktív témák
- Apple MacBook
- NVIDIA GeForce RTX 5080 / 5090 (GB203 / 202)
- Fejhallgató erősítő és DAC topik
- Megérkezett a Samsung Galaxy A37 és Galaxy A57
- Samsung Galaxy A56 - megbízható középszerűség
- Microsoft Office és Office 365 topic
- Okos otthon - Home Assistant, openHAB és más nyílt rendszerek
- TCL LCD és LED TV-k
- Samsung Galaxy Felhasználók OFF topicja
- Telekom otthoni szolgáltatások (TV, internet, telefon)
- További aktív témák...
- Dell Latitude 3410 (i5 10 th gen, 8 GB, 250 GB SSD, FHD) leárazás!!AkciÓÓ
- Asztali PC , Ultra 225F , RTX 5070 , 32GB DDR5 , 1TB NVME
- LOQ 15IRX9 15.6" FHD IPS i7-13650HX RTX 4060 16GB 512GB NVMe gar
- Asztali PC , i7 13700K , RTX 5070 , 32GB RAM , 1,5TB SSD
- Lenovo ThinkPad E590 / Intel Core i7 8GEN / 16gb ram / AMD 2gb dedikált / 500gb NvMe / Vil MAGYAR B
- Óriás! Gamer PC-Számítógép! Csere-Beszámítás! R7 5700 / RTX 3080 / 16GB DDR4 / 512GB SSD!
- Azonnali készpénzes AMD Radeon RX 5000 sorozat videokártya felvásárlás személyesen / csomagküldéssel
- Azonnali készpénzes GAMER / üzleti notebook felvásárlás személyesen / csomagküldéssel korrekt áron
- LG 45GS95QX - 45" Ívelt OLED / 2K WQHD / 240Hz 0.03ms / NVIDIA G-Sync / FreeSync Premium / HDMI 2.1
- Dell Precision 5520 15,6" FHD, Xeon E3-1505M v6, 16GB RAM, Quadro 4GB VGA, SSD, jó akku, számla, gar
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
