0

Prevent Defaults

At the above link it describes how to prevent the default behaviour in JavaScript,but only shows you how to disable all defaults.

I only want to disable Text Selection / Context Menus

How would I go about this? Or am I going about this the wrong way?

This is nessary for the following reasons

  • Disabling paste/copy on the play book
  • When using auto complete the text selector pops up and is very annoying and sometimes in the way

This annoyance is caused by J Query auto select when it shows the text selection in blackberry gets in the way when trying to touch to choose one.

If came up with a work around by adding padding-top:30px; to the auto complete so its below the text selector but would like a better way to do this.

Thanks

.noselect {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -o-user-select: none;
    user-select: none;
}

Tried the above code thanks to a good stack overflower ! and this solves the problem on the browser(e.g chrome) but not on the web works play book application this fully disables editing/input as well which is no good.

4

3 回答 3

4

我认为您不需要javascript来禁用文本选择,CSS就足够了:

.noselect {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -o-user-select: none;
    user-select: none;
}

​<a href="http://jsfiddle.net/ruisoftware/aKkSx/1/" rel="nofollow">jsFiddle 这里

编辑: 要允许在编辑框上键入,同时在那里禁用文本选择,您可以使用此 http://jsfiddle.net/ruisoftware/aKkSx/3/ 基本上撤消jQuery select() 事件上的文本选择。不是最干净的方式,但可能会为您指明正确的方向。

于 2012-07-18T10:51:32.340 回答
1

在 css 文件中包含以下行。

-webkit-user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
user-select: none;
于 2012-07-18T11:00:33.617 回答
0

也可以内联处理。我认为 CSS 解决方案更好,但我总是想知道所有选项:

<element oncontextmenu="return false">
<input onselect="return false">  <!-- only <input>'s though... -->

为了防止选择文本,我认为您必须使用 CSS 或 JS(监听文本上的拖动)或使用图像。
请注意,用户可以访问浏览器显示的所有内容,因此阻止用户选择文本不会阻止他使用 Chrome 检查元素从源代码中删除您的解决方案或从源代码中复制粘贴。

于 2012-07-18T11:13:23.290 回答