[英]Disable select, allow copy/paste
I'm building an app which overrides standard selecting behaviour and allow copying and pasting elements. 我正在构建一个覆盖标准选择行为并允许复制和粘贴元素的应用程序。 The problem is that if I disable selecting, copy events are also gone.
问题是,如果我禁用选择,复制事件也会消失。
I tried using 我试过用
onselectstart="return false;"
and 和
.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;
}
and it works, but it also disable copy event. 它工作,但它也禁用复制事件。
I also tried adding .no-select
attribute only for these parts which contain text, but it is hard to maintain and does not work well - sometimes copy events are blocked and I cannot control it. 我也尝试仅为包含文本的这些部分添加
.no-select
属性,但它很难维护并且不能正常工作 - 有时复制事件被阻止而我无法控制它。
How can I disable select, but enable copy/paste proper way? 如何禁用选择,但启用正确的复制/粘贴方式?
Edit: 编辑:
onCopy
handler. onCopy
处理程序中处理。 When you disabled highlighting/selecting then what you want copy? 当您禁用突出显示/选择时,您想复制什么? Not selected things is still nothing
未选择的东西仍然没有
I don't want to copy text (which is standard behaviour), but my own json representation of objects
我不想复制文本(这是标准行为),而是我自己的json表示对象
Then i have 2 solutions to your problem: 然后我有两个解决你的问题的方法:
Override context menu with function copying to clipboard ( tutorial and library ) 使用函数复制到剪贴板覆盖上下文菜单( 教程和库 )
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; }); }
body { -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; }
<body> Some text </body>
Add "Copy" button with function copying to clipboard ( tutorial and library ) 添加“复制”按钮,功能复制到剪贴板( 教程和库 )
ctrl + c
(and other like command + c
) with function copying to clipboard ( tutorial and library ) ctrl + c
(以及其他类似command + c
)与函数复制绑定到剪贴板( 教程和库 )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.