I would开发者_高级运维 like to prepare a javascript-based system that would deselect the text after the user selects it. The reason for this is to protect some articles on my site from being stolen by just pressing ctrl+c pair. I know it's always possible to omit it, but it's at least a little harder. What is more, I can't use jQuery while writing this script. What do you suggest?
My advice would be not to bother. JavaScript can easily be disabled or manipulated using a script console, source can be viewed and copied, etc. If anyone is going to steal those articles you won't be able to stop them without taking proper legal routes. What's more, you're inconveniencing the folks who have a genuine need to copy and paste something, like a quote or a search term.
That being said, IE, Chrome and Safari all support the onselectstart
event, which is cancellable:
element.onselectstart = function () { return false; }
Firefox supports its own CSS style, -moz-user-select
, which give the appearance that the text isn't selected, but doesn't disable it completely:
#element {
-moz-user-select: none;
}
For Firefox, Opera and other browsers, however, there's no solution other than cancelling mousedown, double click and key events. There would be no way of capturing and blocking "select all" from the browser's menu.
精彩评论