,如果你可以使用jQuery,你可以尝试从pkarl this解决方案:
<script src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
<script type="text/javascript">
$(function() {
// We check for a text selection when someone right-clicks
$(document).bind('contextmenu', checkSelection);
// We also check for a text selection if ctrl/command are pressed along w/certain keys
$(document).keydown(function(ev) {
// capture the event for a variety of browsers
ev = ev || window.event;
// catpure the keyCode for a variety of browsers
kc = ev.keyCode || ev.which;
// check to see that either ctrl or command are being pressed along w/any other keys
if((ev.ctrlKey || ev.metaKey) && kc) {
// these are the naughty keys in question. 'x', 'c', and 'c'
// (some browsers return a key code, some return an ASCII value)
if(kc == 99 || kc == 67 || kc == 88) {
return checkSelection()
}
}
});
})
// check to see if anything is currently highlighted by the visitor. If so, return false.
function checkSelection() {
if (window.getSelection) { var userSelection = window.getSelection(); }
else if (document.selection) { var userSelection = document.selection.createRange(); }
if(userSelection != '') return false;
}
你可以使用jQuery吗? – 2012-08-06 08:33:57
是的,我可以使用Jquery – 2012-08-06 08:39:08
,这是因为IE以任何方式对CSS有蹩脚的支持。 jQuery解决方案没有工作吗? – 2012-08-06 08:59:02