Hirdetés
-
GAMEPOD
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
- Amlogic S905, S912 processzoros készülékek
- Építő/felújító topik
- Stellar Blade
- Sweet.tv - internetes TV
- Autós topik
- Robot fűnyírók
- A fociról könnyedén, egy baráti társaságban
- Milyen videókártyát?
- Locsolkodás helyett hardverekre feni a fogát az ünnepi nyúl
- exHWSW - Értünk mindenhez IS
- További aktív témák...
- Kedvező ár! HP Zbook 15 Workstation laptop (15,6FHD/i7-G4MQ/16GB/128SSD/Nvidia2GB)
- Kedvező ár! Lenovo Yoga 370 laptop-tablet (12,5FHD/i5-G7/16GB/256SSD)
- Újszerű Samsung HW-R470 - 4.1-es hangrendszer wireless hátsó hangfalakkal és mélynyomóval
- Kedvező ár! Lenovo Yoga 260 laptop-tablet (12,5FHD/i5-G7/8GB/256SSD)
- Kedvező ár! Lenovo L380 Touch laptop (14FHD/i5-G8/8GB/256SSD)
- Samsung Galaxy A13 64GB, Kártyafüggetlen, 1 Év Garanciával
- Bezámítás! Lenovo Legion 5 15IMH05H notebook - i5 10300H 16GB DDR4 256GB SSD 1TB HDD GTX 1660Ti W10
- Akció! Újra Gamer EGEREK! Glorious , Endgamer XM1R , Nibio
- BESZÁMÍTÁS! Intel Core i9 13900K 24 mag 32 szál processzor garanciával hibátlan működéssel
- Bezámítás! Lenovo Thinkpad T14 Gen 3 üzleti notebook - i5 1245U 16GB RAM 512GB SSD Intel Iris XeW11
Állásajánlatok
Cég: Laptopszaki Kft.
Város: Budapest
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest