473,396 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Not selectable HTML, with exceptions

Hi there,

I have a quick, but apparently quite complicated question.

I want my whole site to be unselectable, with a few exceptions. Unfortunatly I am not able to do this.

I have a semi working versions, with onselectstart="return false" in the body tag, but then I can't select anything. I also have a version with a function which iterates over the whole HTML and makes everything with "unselectable" in the class name unselectable by:

Expand|Select|Wrap|Line Numbers
  1. function unselectElement(element) {
  2.     element.style.MozUserSelect='none';
  3.     element.style.KhtmlUserSelect='none';
  4.     element.unselectable='on';
  5.     element.onselectstart = function(){return false;};
  6. }
However, this application is extremy AJAX heavy and updated elements loose those assigned attributes/events. I'm using wicket where I would have to append javascript all the time for every single element which appears to be extremly tedious and requires resturucturing of the code as well. (if you have a good solution in this regard, tell me).

Unfortunatly I can't let the "unselectAll" function run after every ajaxrequest, because it's just to slow.

Ideally I could specify that the whole document is unselectable and turn it on for the few elements I want the user to select. Preferably with CSS; but apparently this isn't possible.

An IE-only solution is okay right now, but cross browser solution would be awesome (FF and IE at least).

The reason for this functionality is mostly that I have a lot of dragable objects, which causes a bunch of elements in the background to be selected which looks more than ugly and is confusing for the user. I toy with a "body = unselectable" solution when something is dragged, but it's more of a last resort.

Help would really be much appreciated.

- Tom
Aug 21 '08 #1
2 2958
acoder
16,027 Expert Mod 8TB
Instead of making the whole page non-selectable, why not prevent the dragging of those elements only? That should solve this problem unless I've missed something. In your drag event handler, just check that only the correct elements/objects are allowed to be dragged.
Aug 21 '08 #2
mrhoo
428 256MB
To prevent the body (or other container) content from being selected when you drag an item, stop the mousedown and mousemove events from bubbling up to the body.

Add the event stopping code at the end of the handlers:
Expand|Select|Wrap|Line Numbers
  1. function dragmove(e){
  2.     e=window.event || e;
  3.     // run your dragging code 
  4.  
  5.     event.cancelBubble= true;     //ie
  6.     if(e.stopPropagation) e.stopPropagation();     //others
  7. }
Aug 21 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

71
by: tomy_baseo | last post by:
I'm new to HTML and want to learn the basics by learning to code by hand (with the assistance of an HTML editor to eliminate repetitive tasks). Can anyone recommend a good, basic HTML editor that's...
2
by: Paul | last post by:
Hello, I am trying to make a menu for a html page and I am using DIV tags for buttons. I don't like the idea of being able to select the text, is there a way I can change this behaviour to make...
2
by: Rachel Suddeth | last post by:
Is there a way to have the non-selectable dates (those before MinDate and after MaxDate) draw differently so my users can see right away what dates aren't allowed? I'm not seeing it... ...
5
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
8
by: Gary Owsiany | last post by:
Ok, the silence is deafening. I posted my selectable sort application to show that you can use the IComparable Interface just as effectively as the IComparer Interface and the feedback has been,...
40
by: Paul Davis | last post by:
Hi all, I'm building some style sheets and trying to play the old game of balancing designer pixel perfection and still allowing users to adjust their font sizes. The compromise I've made with the...
1
by: Homer | last post by:
Hi, I used a template for my first Web application. I made a few changes to the layer thru its css file. The problem that has been vexing me is the vertical spacing for each navigation menu...
1
by: dbphoto | last post by:
I've created a selectable layer and inputted the action script into the button but the layer appears on the main layer and is not selectable. Any ideas?
2
by: DMVC | last post by:
Hi all. I've built a class based on "Control" and I want this object of mine to be selectable. I believe that, by default, Control is non-selectable so I used ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.