+ 1

Copying something with a button

When I click to button , It will copy a div's innerHTML can I do that with html5 or javaScript ? -> ctrl + w / right click + copy / ...

24th Jun 2017, 9:14 PM
Serhat Merak
Serhat Merak - avatar
11 Respuestas
+ 5
just so you know the copy you actually wanted to implement will always be implemented already by the environment e.g text editor, browser or operating system(linux, windows etc). The code above doesn't create the copy command but rather display success or failure message. Your image showing the dialogue menu for copy, cut etc are implemented by android environment.
24th Jun 2017, 10:25 PM
Benneth Yankey
Benneth Yankey - avatar
+ 4
good research...👍👍
24th Jun 2017, 10:20 PM
Benneth Yankey
Benneth Yankey - avatar
+ 2
let btn = document. querySelector("button"); btn.addEventListener("click", function(){ // get div with content you want to manipulate let txt = document.querySelector("div").innerHTML; // now u can use "txt" above to control what to do with the content or texts. e.g // you could append another text to it // output the text in another div...etc })
24th Jun 2017, 9:26 PM
Benneth Yankey
Benneth Yankey - avatar
24th Jun 2017, 10:03 PM
Serhat Merak
Serhat Merak - avatar
+ 2
Wow! thought you wanted to learn, instead of upvoting you are thinking of making it your code...Lol. You may go ahead copy and use it OK. I didn't make it public it's your code. Happy coding!
24th Jun 2017, 10:04 PM
Benneth Yankey
Benneth Yankey - avatar
+ 1
Thank you but I want that For example you wrote it for me and I copied it and than I pasted it to my own code
24th Jun 2017, 10:01 PM
Serhat Merak
Serhat Merak - avatar
+ 1
you didn't understood 😂😂😂 could you look that -> https://i.hizliresim.com/5QMWgD.jpg
24th Jun 2017, 10:05 PM
Serhat Merak
Serhat Merak - avatar
+ 1
I want to copy text button
24th Jun 2017, 10:06 PM
Serhat Merak
Serhat Merak - avatar
+ 1
I found -> <p> <textarea class="js-copytextarea">Hello I'm some text</textarea> </p> <p> <button class="js-textareacopybtn">Copy Textarea</button> </p> <script type="text/javascript"> var copyTextareaBtn = document.querySelector('.js-textareacopybtn'); copyTextareaBtn.addEventListener('click', function(event) { var copyTextarea = document.querySelector('.js-copytextarea'); copyTextarea.select(); try { var successful = document.execCommand('copy'); var msg = successful ? 'successful' : 'unsuccessful'; console.log('Copying text command was ' + msg); } catch (err) { console.log('Oops, unable to copy'); } }); </script>
24th Jun 2017, 10:17 PM
Serhat Merak
Serhat Merak - avatar
+ 1
Yes It isn't mine already I found it in stackoverflow so I didn't change it but while I using on my own project I will change I just wanted to learn 😊😊😊
24th Jun 2017, 10:30 PM
Serhat Merak
Serhat Merak - avatar
0
Actually , I don't understood sorry :( Could you write it and share with me ( I want to make "copy text" button )
24th Jun 2017, 9:32 PM
Serhat Merak
Serhat Merak - avatar