- OnePlus 9 Pro - gyorsulási futam
- Magisk
- Honor 200 Pro - mobilportré
- Sony WF-1000XM6 – ez évi etalon?
- Megtartotta Európában a 7500 mAh-t az Oppo
- Apple Watch
- iPhone topik
- Apple iPhone 17 Pro Max – fennsík
- Apple iPhone 16 Pro - rutinvizsga
- Samsung Galaxy Watch8 és Watch8 Classic – lelkes hiperaktivitás
-
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
- Sigma 12-24mm f/4.5-5.6 EX DG HSM
- Eladó 4GB DDR4 laptop RAM-ok (SO-DIMM) többféle órajellel ( 10 darab )
- OHH! MSI CYBORG 15 Gamer Tervező Laptop 15,6" -30% i7-13620H 10Mag 16/512 RTX 4060 8GB FHD 144Hz
- ELADÓ 4 darab 8GB DDR4 ECC Registered (RDIMM) Szerver RAM modul
- Építőipari csomag (vakológépek, targoncák, építőipari eszközök és kellékek, egyéb, sok más)
- Samsung Galaxy S24 FE 128GB, Kártyafüggetlen, 1 Év Garanciával
- Apple iPhone 13 mini 256GB Pink használt, szép állapot 100% akku 6 hónap garancia
- GIGABYTE A520M DS3H AC vadiúj, 3 év névre szóló garancia, WiFi
- BESZÁMÍTÁS! ASUS ROG GL10DH brand számítógép - R7 3700X 32GB DDR4 512GB SSD RTX 2060S 8GB 500W W11
- BESZÁMÍTÁS! Gigabyte H110M i5 7600K 16GB DDR4 240GB SSD GTX 1060 6GB GDDR5 Rampage SHIVA 400W
Állásajánlatok
Cég: Laptopműhely Bt.
Város: Budapest
Cég: Central PC számítógép és laptop szerviz - Pécs
Város: Pécs


