Global Directory
Global Directory
EXPLORE OUR SITES
London Stock Exchange Group
LSEG Data & Analytics
MyAccount
LSEG Perspectives
London Stock Exchange
FTSE Russell
LCH
Contact Us
Home
TR Internal
Avoid or block copy paste page content
Carlos Berdaguer
Hi, anyone had the need to avoid the user to select text from the page being displayed on a browser in order to block the copy paste functionality?
I know there are always ways like accessing source code or even using print screen key, but it'd be intresting to see options no matter the weakness of the method.
Cheers.
Find more posts tagged with
refinitiv-internal
Accepted answers
Pablo Colombo
You could try this:
In most browsers, this can be achieved using CSS:
*.unselectable {
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
}
For IE and Opera, you will need to use the unselectable expando property of the element you wish to be unselectable. You can set this using an attribute in HTML:
...
Sadly this property isn't inherited, meaning you have to put an attribute in the start tag of every element inside the
. If this is a problem, you could instead use JavaScript to do this recursively for an element's descendants:
function makeUnselectable(node) {
if (node.nodeType == 1) {
node.unselectable = true;
}
var child = node.firstChild;
while (child) {
makeUnselectable(child);
child = child.nextSibling;
}
}
makeUnselectable(document.getElementById("foo"));
[link text][1]
[1]:
http://stackoverflow.com/questions/3469900/how-can-i-stop-text-from-being-selected
All comments
Carlos Berdaguer
Forgot to mention: I'm most intrested in options that work for our beloved (sarcasm) IE.
Thanks.
mark.maruska
It seems to me that this sort of topic is not company specific, so I would suspect that there are numerous discussions on the web for this. I suggest starting here or here...
-
https://www.google.com/search?q=prevent+copy+paste+ie
-
http://stackoverflow.com/search?q=prevent+copy+paste+ie
Andrew Halford
If possible, use an embedded Java applet to display the text. This is a specific instance of a more general solution: Display the text within an embedded object, where the object renders the text rather than the browser. So you could also use a video clip, or flash etc.
Pablo Colombo
You could try this:
In most browsers, this can be achieved using CSS:
*.unselectable {
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-o-user-select: none;
user-select: none;
}
For IE and Opera, you will need to use the unselectable expando property of the element you wish to be unselectable. You can set this using an attribute in HTML:
...
Sadly this property isn't inherited, meaning you have to put an attribute in the start tag of every element inside the
. If this is a problem, you could instead use JavaScript to do this recursively for an element's descendants:
function makeUnselectable(node) {
if (node.nodeType == 1) {
node.unselectable = true;
}
var child = node.firstChild;
while (child) {
makeUnselectable(child);
child = child.nextSibling;
}
}
makeUnselectable(document.getElementById("foo"));
[link text][1]
[1]:
http://stackoverflow.com/questions/3469900/how-can-i-stop-text-from-being-selected
Emiliano Claria
I think that one way would be to disable the mouseDown event on the text so it cannot be selected, something like
$("#textdiv").mousedown(function() { return false; });
Some blogs also have some javascript that adds something to the copied text like the original URL to prevent the post from being stolen. I guess that the same type of functionality could be used to replace the copied text to nothing, but I wasn't able to find anything with a quick search.
Carlos Berdaguer
Thanks, are you currently using this in any product?
Quick Links
All Forums
Recent Questions
Terms of use
Privacy & Cookie Statement
Cookies settings
Do not sell my info
Whistleblowing
UK Bribery Act
Modern Slavery Act