![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|||||||||||||||||||||||
|
Image sizes: 256x256, 48x48, 32x32, 24x24, 20x20, 16x16 File formats: BMP, GIF, PNG, ICO ![]() ![]() ![]() ![]() How do I prevent the browser to selecting textIf you are a web developer, you have probably arisen the need to prevent a user from text selection. Reservation that I do not mean a complete ban to protect the text, and a ban on the allocation of various signatures, inscriptions, etc. where selection is interfering with the interface and the user (usually with drag & drop, or select text when you double-click). This is especially true for Web applications, and in any case does not apply to news sites.What can we do? Until now, little thought. But before turning to the new (for me personally) method, consider what opportunities combat text selection we offer browsers. Internet Explorer This browser provides us with two possibilities: 1. For the elements set unelectable attribute with a value on. But there is one nuance: the text block with this attribute can not separate (ie not start with the selection of the element, and click on this element will not remove the selection from the text if this is selected), but if it contains other elements (for example, harmless "SPAN, B, etc.) then the text in them can provide. Moreover, if the selection started with a block of text without such an attribute, then the text inside the block with unelectable attribute will also be highlighted. In such a situation, one solution - to put all (!) Elements of the attribute, which is inconvenient and not practical. 2. Intercepting events selectstart. In other words, adding an element onselectstart = "return false" (for example to BODY) prohibits the provision of the text inside it. Again, nuance: if you start to select text beyond the limits of such a unit, the text inside it stands out without any problems. FireFox (web browsers on the engine gecko), Safari (web browsers on the engine KHTML) These browsers have a better mechanism to prohibit the selection of text in any form. This is done through the CSS property is user-select with the value none, which is included in CSS3. But before this property is approved, browsers democratically made it his own chip engine called property-moz-user-select and-khtml-user-select, respectively. So, to disable select text inside the block, just write: -moz-user-select: none; -khtml-user-select: none; user-select: none; ![]()
| Copyright © 2006-2022 Aha-Soft. All rights reserved. |
|