- Dreame Pilot - Álomhaj, ó!
- Xiaomi 17 Ultra - jó az optikája
- Samsung Galaxy S24+ - a személyi asszisztens
- Hivatalos a OnePlus 13 startdátuma
- Fotók, videók mobillal
- Samsung Galaxy S25 FE - fenséges, felejthető vagy felesleges?
- Brutális akkumulátort kaphat a Honor X80 GT
- iPhone topik
- Xiaomi 14T - nem baj, hogy nem Pro
- Itt a Galaxy S26 széria: az Ultra fejlődött, a másik kettő alig
-
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
- Milyen egeret válasszak?
- Xbox Series X|S
- Anglia - élmények, tapasztalatok
- Autós topik
- Kés topik
- NVIDIA® driverek topikja
- Dreame Pilot - Álomhaj, ó!
- Xiaomi 17 Ultra - jó az optikája
- Ha az alaplapi hangchipnél jobbra váltanál, itt az új Sound Blaster hangkártya
- Samsung Galaxy S24+ - a személyi asszisztens
- További aktív témák...
- Manli RTX 3070 8GB LHR / Csavarmatricás / Beszámítás OK! / Akciós ár!
- Apple Watch 4 44mm szürke színben. 74% akkumulátor.
- Canon EF-S 24mm f/2.8 STM objektív
- Dell Inspiron 16 Plus 7640 Ultra 7 / RTX 4060 16gb DDR5 1TB SSD/2.5K 120Hz Garancia
- Canon 60D fényképezőgép + 50mm objektív + 16GB memóriakártya
- LG 32GS75QX-B - 32" IPS - 2560x1440 - 180Hz 1ms - AMD FreeSync Premium - NVIDIA G-Sync - sRGB 99%
- Sandisk Portable SSD 2TB!
- Xiaomi Redmi Note 14 Pro + 512GB // ÁFÁS számla // GARANCIA //
- Azonnali készpénzes GAMER / üzleti notebook felvásárlás személyesen / csomagküldéssel korrekt áron
- GYÖNYÖRŰ iPhone 15 Pro Max 256GB Blue Titanium-1 ÉV GARANCIA -Kártyafüggetlen, MS4480
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest


