Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <title>Hello World</title>
- </head>
- <body>
- <span id="datamandiri" onclick="pakaimandiri()">1234567890</span>
- <br>
- <br>
- <button type="button" id="copy" onclick="pakaimandiri()">
- Copy Data
- </button>
- <script>
- var mandiri = document.getElementById('datamandiri');
- function pakaimandiri(){
- /* TEKS YANG MAU DI COPY, DI SELECT DULU */
- pilihteks('datamandiri');
- /* PROSES COPY */
- document.execCommand('copy');
- /* UNTUK ANTISIPASI BEBERAPA TIPE BROWSER YANG GA SUPPORT execCommand */
- //navigator.clipboard.writeText(mandiri.textContent);
- /* UNTUK MENGGANTI TULISAN DI TOMBOL */
- document.getElementById('copy').innerHTML = 'Copied';
- alert('Norek Mandiri: ' + mandiri.textContent + ' berhasil disalin');
- }
- /* UNTUK MENYELEKSI TEKS YANG AKAN DICOPY*/
- function pilihteks(containerid) {
- if (document.selection) { // INTERNET EXPLORER/EDGE
- var range = document.body.createTextRange();
- range.moveToElementText(document.getElementById(containerid));
- range.select();
- } else if (window.getSelection) {
- var range = document.createRange();
- range.selectNode(document.getElementById(containerid));
- window.getSelection().removeAllRanges();
- window.getSelection().addRange(range);
- }
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement