feat(wip): 複製到剪貼薄
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
<span slot="headline">错误</span>
|
||||
<span slot="description" id="ErrorDialog_Message"></span>
|
||||
</mdui-dialog>
|
||||
<input style="display: none;" id="copy_to_clipboard_fallback"></input>
|
||||
|
||||
<script nomodule>
|
||||
alert('很抱歉, 此应用无法在较旧的浏览器运行, 请使用基于 Chromium 89+ 的浏览器(内核)使用 :(')
|
||||
|
||||
14
client/ui/copyToClipboard.ts
Normal file
14
client/ui/copyToClipboard.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { $ } from 'mdui/jq'
|
||||
|
||||
export default function copyToClipboard(text: string) {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(text)
|
||||
} else {
|
||||
const input = $('#copy_to_clipboard_fallback').get(0) as HTMLInputElement
|
||||
input.value = text
|
||||
input.select()
|
||||
input.setSelectionRange(0, 1145141919810)
|
||||
document.execCommand('copy')
|
||||
input.clearSelection()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user