Hirdetés
- "A homoszexualitás természetellenes" 😠
- Itt az új LOGOUT!
- Asszociációs játék. :)
- Internet fejlesztés országosan!
- Raspberry Pi Zero W külső antenna újrahasznosított alkatrészekből
- Amazon Fire TV Stick 4K Max 2nd
- Milyen mosógépet vegyek?
- Bestbuy travel, utazós, kirándulós topic - szállások, jegyek
- Nagy "hülyétkapokazapróktól" topik
- Konvektor korszerűsítés - Computherm KonvekPRO felszerelése Q7RF szobatermosztát
-
LOGOUT.hu
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.
[ Szerkesztve ]
ⓑⓣⓩ
Új hozzászólás Aktív témák
Hirdetés
- IPhone 12 Pro 256GB gyári független gyönyörű + ajándék magsafe tok
- Strix 15 GL503GE 15.6" FHD IPS i7-8750H GTX 1050Ti 16GB 256GB NVMe+1TB HDD magyar vbill gar
- CSAK 1DB!!! EZÜST! VADIÚJ BONTATLAN, 2ÉV+ GAROS Surface Pro 9 i5-1235U 16GB 1TB SSD
- CSAK 1DB!!! FEKETE! VADIÚJ BONTATLAN, 2ÉV+ GAROS Surface Pro 9 i5-1235U 16GB 1TB SSD
- Sony Pulse 3D 2026.07.26. Euronics garancia /vásárlás
Állásajánlatok
Cég: Ozeki Kft
Város: Debrecen
Cég: Ozeki Kft
Város: Debrecen