mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-02 23:23:28 +08:00
复制到剪切板功能兼容旧版浏览器
This commit is contained in:
@@ -1,11 +1,42 @@
|
||||
function copyToClipboard(content) {
|
||||
var aux = document.createElement('input');
|
||||
aux.setAttribute('value', content);
|
||||
aux.style.display = "none";
|
||||
document.body.appendChild(aux);
|
||||
aux.select();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(aux);
|
||||
|
||||
// firefox 下必须为用户同步调用,不可以使用异步调用隔开
|
||||
// refer: http://www.caotama.com/43769.html
|
||||
|
||||
function oldMethod() {
|
||||
var aux = document.createElement('input');
|
||||
aux.setAttribute('value', content);
|
||||
// 在 firefox for windows 93.0 版本下测试,添加这一行会无法复制到剪切板
|
||||
// aux.style.display = "none";
|
||||
document.body.appendChild(aux);
|
||||
aux.select();
|
||||
aux.focus();
|
||||
document.execCommand('copy');
|
||||
document.body.removeChild(aux);
|
||||
|
||||
console.log("isSuccess", isSuccess);
|
||||
}
|
||||
if (navigator.clipboard) {
|
||||
navigator.permissions.query({ name: "clipboard-write" }).then(result => {
|
||||
if (result.state == "granted") {
|
||||
navigator.clipboard.writeText(content)
|
||||
.then(function () {
|
||||
// 复制成功
|
||||
console.log("API复制成功");
|
||||
}, function () {
|
||||
// 使用API复制失败
|
||||
console.log("API复制失败");
|
||||
oldMethod();
|
||||
})
|
||||
} else {
|
||||
console.log("支持API,但没有权限,使用旧方法复制");
|
||||
oldMethod();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log("不支持API,使用旧方法复制");
|
||||
oldMethod();
|
||||
}
|
||||
}
|
||||
function showTip(e, text) {
|
||||
var $i = $("<span>").text(text);
|
||||
@@ -25,7 +56,7 @@ function showTip(e, text) {
|
||||
"top": y - 60,
|
||||
"left": x,
|
||||
"opacity": "0"
|
||||
}, 600, function() {
|
||||
}, 600, function () {
|
||||
$i.remove();
|
||||
});
|
||||
e.stopPropagation();
|
||||
|
@@ -100,7 +100,7 @@ router.get('/dashboard/:group/:page/:subpage?', function (req, res) {
|
||||
},
|
||||
"category-manage": {
|
||||
title: "分类管理",
|
||||
baseTemplate: "form",
|
||||
baseTemplate: "table",
|
||||
pageTemplate: "CategoryManage",
|
||||
},
|
||||
"book-manage": {
|
||||
|
Reference in New Issue
Block a user