Hirdetés
- One mobilszolgáltatások
- Redmi Note 13 Pro+ - a fejlődés íve
- Honor Magic6 Lite - bűvös hatos
- Xiaomi 13 - felnőni nehéz
- Xiaomi 14T - nem baj, hogy nem Pro
- Mobil flották
- CMF Watch Pro 2 - ebből a poénból többet is ki lehetett volna hozni
- Samsung Galaxy Watch6 Classic - tekerd!
- Samsung Galaxy A35 5G - fordulópont
- Motorola Edge 30 Neo - wake up, Jr...
-
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
- Samsung Galaxy Watch Ultra LTE 47mm, Újszerű, 1 Év Garanciával
- Tablet+laptop egyben (i5 7.gn, 250GB SSD, 16 GB, FHD)! AkciÓÓ
- Karcmentes Apple iPhone 15 Pro Max 256GB Black Titanium 1OO% !! még 2 Hó nemzetközi APPLE GaranciA
- FÉL ÁR ALATT! Lian Li UNI FAN SL120 RGB 1db-os és 3db-os ventilátor szett garanciával
- ÚJ Bontatlan Apple Watch Ultra 2 TiTanium 49mm !! aktiválástól 1ÉV Nemzetközi APPLE GaranciáVAL
- Bomba ár! Lenovo ThinkPad X270 - i5-6G I 8GB I 256GB SSD I 12,5" FHD I HDMI I Cam I W10 I Garancia!
- Samsung Galaxy A14 64GB, Kártyafüggetlen, 1 Év Garanciával
- Bomba ár! Dell Latitude 5320 - i5-1145G7 I 16GB I 256SSD I HDMI I 13,3" FHD I Cam I W11 I Garancia!
- Logitech MX Magyar Business Windows Edition HU Átalakítás és testreszabás / mx keys
- ÁRGARANCIA!Épített KomPhone Ryzen 9 5900X 16/32/64GB RAM RTX 5070 12GB GAMER PC termékbeszámítással
Állásajánlatok
Cég: Liszt Ferenc Zeneművészeti Egyetem
Város: Budapest