Hirdetés
- MIUI / HyperOS topik
- iPhone topik
- Samsung Galaxy A54 - türelemjáték
- Xiaomi 15 - kicsi telefon nagy energiával
- Samsung Galaxy Watch6 Classic - tekerd!
- Samsung Galaxy S23 Ultra - non plus ultra
- Rossz hírek a Galaxy S26-ok teléjét illetően
- Apple iPhone 16 Pro - rutinvizsga
- Apple iPhone 15 Pro Max - Attack on Titan
- Huawei Watch GT 6 és GT 6 Pro duplateszt
-
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
- -ÚJ,2 ÉV GAR- GAMER PC: RYZEN 5 4500-5600X +RX 6600/6700XT +16-64GB DDR4! SZÁMLA! 70 féle ház!
- MacBook Pro 14 (2021) M1 Pro / 16 GB RAM / 512 GB SSD Új topcase, 100% akku
- Yamaha R-N402D sztereó erősítő
- HP ProBook 450 G7, 15,6" FHD IPS, I5-10210U, 8GB DDR4, 256GB SSD, W11, Számla, 1 év garancia ( olvas
- Apple MacBook Pro M2 12 C 16 GB/ 1 TB HUN 2023
- ÁRGARANCIA!Épített KomPhone Ryzen 5 7600X 32/64GB RAM RTX 5070 12GB GAMER PC termékbeszámítással
- ÁRGARANCIA!Épített KomPhone Ryzen 5 7500F 32/64GB RAM RX 7800 XT 16GB GAMER PC termékbeszámítással
- ÁRGARANCIA!Épített KomPhone Ryzen 5 7600X 32/64GB RAM RTX 5060 Ti 8GB GAMER PC termékbeszámítással
- BESZÁMÍTÁS! ASUS H510M i5 10500T 16GB DDR4 512GB SSD RX 5500 XT 8GB Zalman T4 Plus Chieftec 600W
- Honor 90 512GB, Kártyafüggetlen, 1 Év Garanciával
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: NetGo.hu Kft.
Város: Gödöllő


