Hirdetés
- OLED TV topic
- 30 évre csökkentette lemaradását a litográfiai eszközök területén Oroszország
- Milyen billentyűzetet vegyek?
- Amazon Fire TV stick/box
- NVIDIA GeForce RTX 5080 / 5090 (GB203 / 202)
- Bambu Lab 3D nyomtatók
- Gigantikus igényt adott le a H20 gyorsítóra több kínai cég
- ZIDOO médialejátszók
- AMD Navi Radeon™ RX 9xxx sorozat
- Socket AM4
-
PROHARDVER!
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
- Honor 200 Pro - mobilportré
- OLED TV topic
- 30 évre csökkentette lemaradását a litográfiai eszközök területén Oroszország
- iPhone topik
- Sekiro: Shadows Die Twice
- Samsung Galaxy S24 Ultra - ha működik, ne változtass!
- Huawei Watch GT 5 Pro - egészség + stílus
- Építő/felújító topik
- Telekom mobilszolgáltatások
- Kerékpárosok, bringások ide!
- További aktív témák...
- Nintendo Switch OLED Mario Red Limited Edition Garanciális
- Lenovo Thinkpad T14s G2 Üzleti "Golyóálló" Laptop 14" -50% i7-1185G7 4Mag 16GB/1TB FHD IPS
- Lenovo Thinkpad T14s G2 Üzleti "Golyóálló" Laptop 14" -50% i7-1185G7 4Mag 16GB/512GB FHD IPS
- Eladó ritkaság! Honor Magic 4 Ultimate!
- Szép állapotban lévő iPhone 14, 128Gb (kék) eladó
- ÁRGARANCIA!Épített KomPhone i5 13400F 32/64GB RAM RTX 4060 Ti 8GB GAMER PC termékbeszámítással
- LG 55CS6 - 55" OLED - 4K 120Hz 1ms - NVIDIA G-Sync - FreeSync Premium - HDMI 2.1 - PS5 és Xbox!
- Új! HP 230 Vezetéknélküli USB-s Billentyűzet
- Samsung Galaxy A55 5G 256GB, Kártyafüggetlen, 1 Év Garanciával
- BESZÁMÍTÁS! GIGABYTE B360 i5 9600K 16GB DDR4 512GB SSD RX 7600 8GB Rampage SHIVA Zalman 600W
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest