- Motorola Moto G06 Power – nagyfater új zakót vett
- Redmi Note 13 Pro 5G - nem százas, kétszázas!
- Samsung Galaxy S23 és S23+ - ami belül van, az számít igazán
- Honor Magic6 Pro - kör közepén számok
- Garmin Instinct – küldetés teljesítve
- Samsung Galaxy S23 Ultra - non plus ultra
- iPhone topik
- Motorola Edge 50 Fusion - jó fogás
- Xiaomi 17 - még mindig tart
- One mobilszolgáltatások
-
Mobilarena
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
- ASUS TUF A15 - 15.6"FHD 144Hz - Ryzen 7 7445HS - 16GB - 512GB - Win11 - RTX 3050 - Garancia
- Innosick, Samsung Laptop memória DDR5 5600Mhz // ÚJ // Számla // Garancia //
- Új Gamer PC - Ryzen 7 5700X / RX 9060 XT 16GB / B550M WIFI / 32GB RAM 3600MHz / 1TB NVMe SSD
- Panasonic ToughBook FZ-55-2 11.gen. I5 laptop (Intel I5-1145G7 8X4400 Mhz, 16GB DDR4, 512GB NVME)
- Precision 3560 15.6" FHD IPS i7-1165G7 T500 32GB 512GB NVMe IR kam gar
- 210 - Lenovo IdeaPad 5 Pro (16ARH7) - AMD Ryzen 7 6800HS, RTX 3050Ti
- BESZÁMÍTÁS! MSI B450 R7 1700 16GB DDR4 512GB SSD GTX 1070 8GB Rampage SHIVA Thermaltake 500W
- REFURBISHED - HP USB-C Universal Dock G1 (DisplayLink)
- Xiaomi Mi Note 10 Lite 128GB, Kártyafüggetlen, 1 Év Garanciával
- iPhone 12 Pro 128GB 100% (3hónap garancia)- ÚJ EREDETI AKKUMULÁTOR - AKCIÓ
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest


