Hirdetés
- Milyen notebookot vegyek?
- Nem tetszik pár profi eSport játékosnak, hogy Intel CPU-val kell játszaniuk
- AMD K6-III, és minden ami RETRO - Oldschool tuning
- OLED TV topic
- Nem okoz az adattárolón hibát a Windows 11 augusztusi frissítése
- SSD kibeszélő
- Mikrokontrollerek Arduino környezetben (programozás, építés, tippek)
- Nvidia GPU-k jövője - amit tudni vélünk
- Milyen HASZNÁLT notebookot vegyek?
- Milyen asztali (teljes vagy fél-) gépet vegyek?
-
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
- Vírusirtó topic
- Windows 11
- Milyen notebookot vegyek?
- Nem tetszik pár profi eSport játékosnak, hogy Intel CPU-val kell játszaniuk
- Milyen okostelefont vegyek?
- Assetto Corsa EVO
- AMD K6-III, és minden ami RETRO - Oldschool tuning
- Oldalról rápillanthatunk a Vivo X300-ak kameráira
- OLED TV topic
- Érintésnélküli fizetési megoldások - PayPass via NFC
- További aktív témák...
- Enermax Liqmax III ARGB 360 (3/2 ventis) INGYEN FOXPOST
- MacBook Air M3 13.6" 8/256 100% akkumulátor
- Eladó egy oneplus 9 pro 256/12
- !!AKCIÓ!! AppleCare+ biztosítás és kiterjesztett garancia - Apple hivatalos biztosítás - Számlával
- Enermax ETS-T50 W-ARGB (Brutál hiányos+hibás alkatrésznek csakis) INGYEN FOXPOST
- Keresünk dokkolókat
- Telefon felvásárlás!! Samsung Galaxy S23/Samsung Galaxy S23+/Samsung Galaxy S23 Ultra
- Bomba ár! Asus X540YA - AMD A8 I 8GB I 512SSD I Radeon I 15,6" FHD I Cam I W10 I Garancia!
- 143 - Lenovo LOQ (15IRH8) - Intel Core i5-13500H, RTX 4060
- Apple iPhone 15 Pro Max 256GB, Kártyafüggetlen, 1 Év Garanciával
Állásajánlatok
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest
Cég: CAMERA-PRO Hungary Kft.
Város: Budapest