- Samsung Galaxy S25 - végre van kicsi!
- Xiaomi 17 - még mindig tart
- Szerény teleppel érkezik a Galaxy A37/A57
- Xiaomi 17 Ultra - jó az optikája
- Nothing Phone 2a - semmi nem drága
- Milyen okostelefont vegyek?
- Yettel topik
- CMF Phone 1 - egy jó telefon
- Dobja a kapszulát és 8000 mAh fölé lő a Honor kompaktja
- Samsung Galaxy S23 és S23+ - ami belül van, az számít igazán
-
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
- Azta! Dell Latitude 7440 -65% Üzleti Profi Fémházas Ultrabook Laptop 14" i7-1365U 32/512 FHD IRIS Xe
- DJI Osmo Action 4 Adventure Combo + sok tartozékkal búvárkodáshoz
- Samsung 32GB DDR4-2666V 2 x 16 GB (M393A2K43BB1-CTD6Q) Szerver memória
- Felújított (Refurbished) DELL Latitude 5430 Tartós Üzleti Laptop 14" -70% i5-1235U 10Mag 16/512 FHD
- HP ProBook 450 G8, 15,6" FHD, i5-1135G7 CPU, 8GB DDR4, 256GB SSD, W11, Számla, 1 év garancia ( olvas
- ÁRGARANCIA!Épített KomPhone Ryzen 5 5600X 16/32/64GB RAM RX 7600 8GB GAMER PC termékbeszámítással
- Lenovo Legion Slim 5 Ryzen 7 7840HS 16GB 1000GB RTX 4060 OLED 120Hz 1év garancia
- GAMER PC! Ryzen 5800X / RX 7700 XT / 32GB DDR4 / 1TB SSD / 650w Gold!
- HIBÁTLAN iPhone 15 Pro 128GB Natural Titanium -1 ÉV GARANCIA - Kártyafüggetlen, MS4384
- PC Architech NOVA Gamer PC
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest


