Hirdetés
- Milyen okostelefont vegyek?
- MIUI / HyperOS topik
- iPhone topik
- Youtube Android alkalmazás alternatívák reklámszűréssel / videók letöltése
- Hivatalos a OnePlus 13 startdátuma
- Sagem MyX-8
- Samsung Galaxy A54 - türelemjáték
- Samsung Galaxy S25 Ultra - titán keret, acélos teljesítmény
- Xiaomi 14T Pro - teljes a család?
- Magisk
-
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
- Linux kezdőknek
- Fortnite - Battle Royale & Save the World (PC, XO, PS4, Switch, Mobil)
- A fociról könnyedén, egy baráti társaságban
- Milyen okostelefont vegyek?
- MIUI / HyperOS topik
- Házimozi belépő szinten
- Vicces képek
- OTP Bank topic
- Sub-ZeRo: Euro Truck Simulator 2 & American Truck Simulator 1 (esetleg 2 majd, ha lesz) :)
- iPhone topik
- További aktív témák...
- Samsung SyncMaster 930BF 19" 1280 x 1024 DVI!
- Lenovo LOQ 15IRH8 - 15.6"FHD IPS 144Hz - i5-12450H - 16GB - 512GB - RTX 4050 - Win11 PRO - 1 év gari
- RTX5070/ Ultra9 275HX/ 32GB DDR5/ 15.1' OLED/ Premium Care garancia/ bontatlan, új/ Legion 5
- NZXT Kraken Z53 RGB(fehér)+NZXT H5 Elite ATX(fehér) garancia 2026.01.31-ig
- Apple Watch Ultra, Újszerű,Dobozával, 12 hónap garanciával
- Dell Latitude 7410 karbon i7 10610U, 16GB RAM, SSD, jó akku, számla, 6 hó gar
- HIBÁTLAN iPhone 13 Pro 128GB Graphite -1 ÉV GARANCIA - Kártyafüggetlen, MS3747, 100% Akkumulátor
- Gamer PC-Számítógép! Csere-Beszámítás! Ryzen 5 8400F / 32GB DDR5 / RX 7800XT 16Gb / 1TB SSD!
- Gamer PC-Számítógép! Csere-Beszámítás! R5 5500 / RX 5700XT 8GB / 32GB DDR4 / 500GB SSD
- Elden Ring PS5 játék
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest


