mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-03 07:32:51 +08:00
复制到剪切板功能兼容旧版浏览器
This commit is contained in:
@@ -1,11 +1,42 @@
|
|||||||
function copyToClipboard(content) {
|
function copyToClipboard(content) {
|
||||||
var aux = document.createElement('input');
|
|
||||||
aux.setAttribute('value', content);
|
// firefox 下必须为用户同步调用,不可以使用异步调用隔开
|
||||||
aux.style.display = "none";
|
// refer: http://www.caotama.com/43769.html
|
||||||
document.body.appendChild(aux);
|
|
||||||
aux.select();
|
function oldMethod() {
|
||||||
document.execCommand('copy');
|
var aux = document.createElement('input');
|
||||||
document.body.removeChild(aux);
|
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) {
|
function showTip(e, text) {
|
||||||
var $i = $("<span>").text(text);
|
var $i = $("<span>").text(text);
|
||||||
@@ -25,7 +56,7 @@ function showTip(e, text) {
|
|||||||
"top": y - 60,
|
"top": y - 60,
|
||||||
"left": x,
|
"left": x,
|
||||||
"opacity": "0"
|
"opacity": "0"
|
||||||
}, 600, function() {
|
}, 600, function () {
|
||||||
$i.remove();
|
$i.remove();
|
||||||
});
|
});
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
@@ -100,7 +100,7 @@ router.get('/dashboard/:group/:page/:subpage?', function (req, res) {
|
|||||||
},
|
},
|
||||||
"category-manage": {
|
"category-manage": {
|
||||||
title: "分类管理",
|
title: "分类管理",
|
||||||
baseTemplate: "form",
|
baseTemplate: "table",
|
||||||
pageTemplate: "CategoryManage",
|
pageTemplate: "CategoryManage",
|
||||||
},
|
},
|
||||||
"book-manage": {
|
"book-manage": {
|
||||||
|
Reference in New Issue
Block a user