Hirdetés
- AMD K6-III, és minden ami RETRO - Oldschool tuning
- Kormányok / autós szimulátorok topikja
- NVIDIA GeForce RTX 5070 / 5070 Ti (GB205 / 203)
- Mini-ITX
- OLED TV topic
- Vezetékes FÜLhallgatók
- Vezeték nélküli fülhallgatók
- Fejhallgató erősítő és DAC topik
- CES 2026: igazi mindenes a Lenovo legújabb, 4K-s QD-OLED monitora
- Fujifilm X
-
PROHARDVER!
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
- AMD K6-III, és minden ami RETRO - Oldschool tuning
- One mobilszolgáltatások
- Audi, Cupra, Seat, Skoda, Volkswagen topik
- Luck Dragon: Asszociációs játék. :)
- Kormányok / autós szimulátorok topikja
- Renault, Dacia topik
- Apple iPhone 17 - alap
- Mibe tegyem a megtakarításaimat?
- exHWSW - Értünk mindenhez IS
- A fociról könnyedén, egy baráti társaságban
- További aktív témák...
- Xiaomi 15 (12GB/256GB - Zöld, 2028.09.05-ig garanciás, újszerű) + ajándék Nillkin Super Frosted tok
- DJI NEO Fly More Combo drón 3 akkumulátorral +Care Refresh +táska
- Lenovo IdeaPad B50-80, 15,6" HD, i3-5005 CPU, 8GB DDR3, 128GB SSD, W11, Számla, 1 év garancia ( ol
- HP EliteBook 840 G3, 14" HD, i5-6300U CPU, 8GB DDR4, 128GB M.2 SSD, W11, Számla, 1 év garancia ( o
- HP EliteBook 840 G2, 14" HD, i5-5300U CPU, 8GB DDR3, 128GB SSD, W11, Számla, 1 év garancia ( olvas
- Xiaomi 14T /12/256GB / Kártyafüggetlen / 12Hó Garancia
- ÁRGARANCIA!Épített KomPhone Ryzen 5 7600X 32/64GB RAM RTX 5070 12GB GAMER PC termékbeszámítással
- Ulefone Armor Pad 5 Pro
- ÁRGARANCIA!Épített KomPhone i5 14600KF 32/64GB DDR5 RAM RTX 5070Ti 16GB GAMER PC termékbeszámítással
- Apple iPhone 12 Mini 64GB, Kártyafüggetlen, 1 Év Garanciával
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: Laptopszaki Kft.
Város: Budapest


