rem*_*ezx 6 html javascript css html5 google-chrome
我正在构建一个覆盖标准选择行为并允许复制和粘贴元素的应用程序.问题是,如果我禁用选择,复制事件也会消失.
我试过用
onselectstart="return false;"
Run Code Online (Sandbox Code Playgroud)
和
.no-select {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
Run Code Online (Sandbox Code Playgroud)
它工作,但它也禁用复制事件.
我还尝试.no-select仅为包含文本的这些部分添加属性,但它很难维护并且不能很好地工作 - 有时复制事件被阻止而我无法控制它.
如何禁用选择,但启用正确的复制/粘贴方式?
编辑:
onCopy处理程序中处理.当您禁用突出显示/选择时,您想要复制什么?没选好的东西还是啥都没有
我不想复制文本(这是标准行为),而是复制我自己的对象的 json 表示
那么我对你的问题有两个解决方案:
if (document.addEventListener) {
document.addEventListener('contextmenu', function(e) {
alert("Write own menu with copy");
e.preventDefault();
}, false);
} else {
document.attachEvent('oncontextmenu', function() {
alert("Write own menu with copy");
window.event.returnValue = false;
});
}Run Code Online (Sandbox Code Playgroud)
body {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}Run Code Online (Sandbox Code Playgroud)
<body>
Some text
</body>Run Code Online (Sandbox Code Playgroud)
ctrl + c(和其他类似command + c),并将功能复制到剪贴板(教程和库)| 归档时间: |
|
| 查看次数: |
913 次 |
| 最近记录: |