开发者

ctrl-c does not copy text on a webpage

开发者 https://www.devze.com 2023-02-01 15:28 出处:网络
I\'ve come across this several times, ctrl-c randomly does not copy. I think it\'s开发者_运维知识库 caused by javascript or maybe some odd html syntax. I never spent the time to track down what caused

I've come across this several times, ctrl-c randomly does not copy. I think it's开发者_运维知识库 caused by javascript or maybe some odd html syntax. I never spent the time to track down what caused it. Anyone know the typical/common causes of ctrl-c not working (to copy) on a website?

Speaking from a developers standpoint. What do we developers end up doing to break ctrl-c?

Just to clarify, I'm not interested in preventing copying. I'm trying to do the opposite, occasionally I find I've done something that is preventing ctrl-c from copying text, and that is not very user friendly on a text heavy site.

To be even more clear, the issue is not with selecting. You can select text just fine. When pressing ctrl-c to copy, it does nothing. I.E. I have text selected, then press ctrl-c and nothing happens.


I've found this sort of thing commonly happens when you're trapping keyboard events to provide your own shortcuts and the code behind it is overly greedy. So you intend to give the user a ctrl-U shortcut for making a unicorn appear on the page, but in your event handler, you create a unicorn when ctrl is pressed along with U — but swallow all other events on the page involving ctrl.


I found something here... http://www.brownielocks.com/stopcopying.html The above link will teach you how to prevent people from right clicking on your website, thus making it more difficult for someone to right click and copy for instance. Please be aware though that there are many ways people can steal content from your site and implementing something like the link above suggests will only prevent the most novice users from making any progress.

Best of luck


It would usually be done on purpose. There's a post on "My Blog Log" that describes a small snippit of javascript that disables copy/paste:

<!-- Disable Copy and Paste-->
<script language='JavaScript1.2'>
function disableselect(e){
return false
}
function reEnable(){
return true
}
document.onselectstart=new Function (&quot;return false&quot;)
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}
</script>

As far as accidentally breaking ctrl+c, it could be an issue with overlapping content divs in some browsers. With some browsers you can prevent text from being selected entirely by placing an invisible div on top of the content.

Also, if something on the page is listening to key events (javascript or flash) it can interfere with browser hotkeys.


If you use this css, this is the problem!!

-webkit-touch-callout: none;

-webkit-user-select: none;

-khtml-user-select: none;

-moz-user-select: none;

-ms-user-select: none;

user-select: none;
0

精彩评论

暂无评论...
验证码 换一张
取 消