Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H5端,复制失败后创建的textarea未销毁。 #2

Closed
1963331542 opened this issue Aug 9, 2021 · 0 comments
Closed

H5端,复制失败后创建的textarea未销毁。 #2

1963331542 opened this issue Aug 9, 2021 · 0 comments

Comments

@1963331542
Copy link

1963331542 commented Aug 9, 2021

这是改进后的代码
export function setClipboardData(data) {
return new Promise((success, fail) => {
// #ifndef H5
uni.setClipboardData({
data,
success,
fail
})
// #endif
// #ifdef H5
const textarea = document.createElement('textarea')
try {
textarea.value = data
textarea.readOnly = true
document.body.appendChild(textarea)
textarea.select()
textarea.setSelectionRange(0, data.length)
document.execCommand('copy')
textarea.remove()
success(data)
} catch (error) {
textarea.remove()
fail(error)
}
// #endif
})
}

@ponjs ponjs closed this as completed Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants