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.
How can I disable select, but enable copy/paste proper way?
Edit:
onCopy
handler.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
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)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With