copy text in vuejs and javascript
Reference:
https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
https://www.w3schools.com/howto/howto_js_copy_clipboard.asp
https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
fallbackCopyTextToClipboard(text) {
var textArea = document.createElement("textarea")
textArea.value = text
textArea.style.position="fixed" //avoid scrolling to bottom
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
try {
var successful = document.execCommand('copy')
var msg = successful ? 'successful' : 'unsuccessful'
console.log('Fallback: Copying text command was ' + msg)
} catch (err) {
console.error('Fallback: Oops, unable to copy', err)
}
document.body.removeChild(textArea)
},
copyTextToClipboard(text) {
if (!navigator.clipboard) {
this.fallbackCopyTextToClipboard(text)
return
}
navigator.clipboard.writeText(text).then(function() {
console.log('Async: Copying to clipboard was successful!')
}, function(err) {
console.error('Async: Could not copy text: ', err)
})
},
https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
https://www.w3schools.com/howto/howto_js_copy_clipboard.asp
https://hackernoon.com/copying-text-to-clipboard-with-javascript-df4d4988697f
copyAddress() {
if (!navigator.clipboard) {
var copyText = document.getElementById('Address')
copyText.focus();
copyText.select()
copyText.setSelectionRange(0, 99999)
// document.execCommand('copy')
try {
var successful = document.execCommand('copy')
var msg = successful ? 'successful' : 'unsuccessful'
console.log('Fallback: Copying text command was ' + msg)
} catch (err) {
console.error('Fallback: Oops, unable to copy', err)
}
} else {
navigator.clipboard.writeText(this.BuyerObj.Address).then(function() {
// console.log('Async: Copying to clipboard was successful!')
},function(err) {
// console.error('Async: Could not copy text: ', err)
})
}
}
fallbackCopyTextToClipboard(text) {
var textArea = document.createElement("textarea")
textArea.value = text
textArea.style.position="fixed" //avoid scrolling to bottom
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
try {
var successful = document.execCommand('copy')
var msg = successful ? 'successful' : 'unsuccessful'
console.log('Fallback: Copying text command was ' + msg)
} catch (err) {
console.error('Fallback: Oops, unable to copy', err)
}
document.body.removeChild(textArea)
},
copyTextToClipboard(text) {
if (!navigator.clipboard) {
this.fallbackCopyTextToClipboard(text)
return
}
navigator.clipboard.writeText(text).then(function() {
console.log('Async: Copying to clipboard was successful!')
}, function(err) {
console.error('Async: Could not copy text: ', err)
})
},
Strange "water hack" burns 2lbs overnight
回复删除Well over 160k men and women are trying a simple and secret "water hack" to drop 2 lbs each night while they sleep.
It is scientific and works with anybody.
You can do it yourself by following these easy steps:
1) Get a glass and fill it with water half the way
2) And then do this amazing HACK
so you'll be 2 lbs lighter when you wake up!