开发者

HTML text unselectable but with a twich ! UNDELETABLE

I know about -moz-user-select: none; -webkit-user-select: none; -khtml-user-select: none; and it works fine in the code i have .

But i want to make my div unselectable by Ctrl+A also, which the above directives don't seem to have an effect on.

How can i disable this selection in Firefox for example? I want to be able to prevent selection with Ctrl+A so that the D开发者_开发问答el key won't delete the text. I want to make the text un-deletable.

Thanks a lot!


You can disable to the Ctrl-A keypress as follows but this won't do the whole job, since the browser's context and Edit menus will still have "Select All" options.

document.onkeydown = function(e) {
    e = e || window.event;
    if (e.ctrlKey && e.keyCode == 65) {
        return false;
    }
};


Using this with the CSS above:

::selection {
        background: rgba(0,0,0,0);
        }
::-moz-selection {
        background: rgba(0,0,0,0);
}

Won't necessarily make it unselectable, but the user won't be able to see what's being selected. ;)

Edit: In response to your comment below, take a look at this: http://jsfiddle.net/Shaz/fM8p4/


It's not entirely clear what you're trying to do; are you looking for something like this:

<div contenteditable="true">
  This part is editable.
  <div contenteditable="false">
    This part is not editable or deletable.
  </div>
  This part is editable again.
<div>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜