Created
May 3, 2018 02:39
-
-
Save ex-hota911/1ce63166551c6df2f4b9bfd4078168ea to your computer and use it in GitHub Desktop.
Bookmarklet to copy the page title and the URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:(function()%7Bconst%20el%20%3D%20document.createElement('textarea')%3Bconst%20str%20%3D%20document.title%20%2B%20'%20-%20'%20%2B%20document.URL%3Bel.value%20%3D%20str%3Bel.setAttribute('readonly'%2C%20'')%3Bel.style.position%20%3D%20'absolute'%3Bel.style.left%20%3D%20'-9999px'%3Bdocument.body.appendChild(el)%3Bel.select()%3Bconst%20result%20%3D%20document.execCommand('copy')%3Bdocument.body.removeChild(el)%3Bif%20(result)%20%7Balert('copied%20%22'%20%2B%20str%20%2B%20'%22')%3B%7D%20else%20%7Balert('copy%20failed')%3B%7D%7D)() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const el = document.createElement('textarea'); | |
| const str = document.title + ' - ' + document.URL; | |
| el.value = str; | |
| el.setAttribute('readonly', ''); | |
| el.style.position = 'absolute'; | |
| el.style.left = '-9999px'; | |
| document.body.appendChild(el); | |
| el.select(); | |
| const result = document.execCommand('copy'); | |
| document.body.removeChild(el); | |
| if (result) { | |
| alert('copied "' + str + '"'); | |
| } else { | |
| alert('copy failed'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment