Hirdetés
-
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
- Garanciális Gamer Számítógép, PC (RX 6600 8GB, Ryzen 5 2600x, 16GB RAM, SSD) Beszámitás, Posta ok!
- MSI RTX 3060Ti 8GB Videókártya /Jótállással!/Dobozos!/Beszámitás!/Posta ok!
- AKCIÓS - Újszerű 18TB Western Digital HC550, WD HC 550 szerver grade SATA HDD
- Palit GeForce Dual RTX 3060 Ti 8GB GDDR6 - Számla + Garancia
- Lenovo Thinkpad P53 / több darab / Áfás számla / HU BILL
- Új, bontatlan Nothing Ear 2 fehér vezeték nélküli fülhallgató - 2 év magyar bolti garanciával! -
- Kingston DDR2 DIMM RAM 8 GB - 667 Mhz - 4 db
- MacBook Air 13 M3 asztroszürke / 16GB ram / 256GB SSD / garancia 2027 december 19-ig
- Eladó Kingston HyperX Fury 4x4 GB DDR4 3200Mhz RAM
- iPhone 15 Pro 128 GB Natúr Titán
- ÁRGARANCIA!Épített KomPhone i9 14900KF 32/64GB RAM RX 7900 XTX 24GB GAMER PC termékbeszámítással
- ÁRGARANCIA! Épített KomPhone Ryzen 5 7600X 32/64GB RAM RTX 5070 12GB GAMER PC termékbeszámítással
- Samsung Galaxy S22 5G 128GB, Kártyafüggetlen, 1 Év Garanciával
- Huawei P Smart 32GB / Normál állapotban / 12 hónap jótállással
- BESZÁMÍTÁS! ASROCK H310CM i5 9600K 32GB DDR4 240GB SSD 1TB HDD RX 5700 8GB Rampage SHIVA FSP 600W
Állásajánlatok
Cég: Laptopszaki Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest